Spring JMS和Websphere MQ

我是Spring JMS和Websphere MQ的新手。任何人都可以给我逐步的过程或示例,以了解如何从Websphere MQ接收消息并能够在控制台中打印该消息吗?非常感谢你的帮助

回答:

这是使用Spring MDP / Activation Spec for Websphere MQ的工作示例

mdp-listener.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"

"http://www.springframework.org/dtd/spring-beans.dtd">

<bean id="messageListener" class="com.rohid.samples.SpringMdp" />

<bean class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">

<property name="activationSpec">

<bean class="com.ibm.mq.connector.inbound.ActivationSpecImpl">

<property name="destinationType" value="javax.jms.Queue"/>

<property name="destination" value="QUEUE1"/>

<property name="hostName" value="A.B.C"/>

<property name="queueManager" value="QM_"/>

<property name="port" value="1414"/>

<property name="channel" value="SYSTEM.ADMIN.SVNNN"/>

<property name="transportType" value="CLIENT"/>

<property name="userName" value="abc"/>

<property name="password" value="jabc"/>

</bean>

</property>

<property name="messageListener" ref="messageListener"/>

<property name="resourceAdapter" ref="myResourceAdapterBean"/>

</bean>

<bean id="myResourceAdapterBean" class ="org.springframework.jca.support.ResourceAdapterFactoryBean">

<property name="resourceAdapter">

<bean class="com.ibm.mq.connector.ResourceAdapterImpl">

<property name="maxConnections" value="50"/>

</bean>

</property>

<property name="workManager">

<bean class="org.springframework.jca.work.SimpleTaskWorkManager"/>

</property>

</bean>

</beans>

web.xml

<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/context/mdp-listener.xml</param-value>

</context-param>

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

SpringMdp

   package com.rohid.samples;

import javax.jms.JMSException;

import javax.jms.Message;

import javax.jms.MessageListener;

import javax.jms.TextMessage;

public class SpringMdp implements MessageListener {

public void onMessage(Message message) {

try {

if(message instanceof TextMessage) {

System.out.println(this + " : " + ((TextMessage) message).getText());

}

} catch (JMSException ex){

throw new RuntimeException(ex);

}

}

}

以上是 Spring JMS和Websphere MQ 的全部内容, 来源链接: utcz.com/qa/398239.html

回到顶部