繁体   English   中英

Spring JMS 和 Websphere MQ

[英]Spring JMS and 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>

网页.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>

春季MDP

   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 Boot JMS Starter 开始

添加一个提供 MQQueueConnectionFactory 的 bean

@Configuration
@EnableJms
public class MQConfiguration {
    @Bean
    public MQQueueConnectionFactory mqFactory()
    {
        MQQueueConnectionFactory    factory = null;
        try {
            factory     = new MQQueueConnectionFactory();
            factory.setHostName("localhost");
            factory.setPort(1414);
            factory.setQueueManager("QM.LOCAL");
            factory.setChannel("SYSTEM.DEF.SVRCONN");
            factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
        }
        catch (JMSException e) {
            System.out.println(e);
        }
        return factory;
    }
}

删除对 org.apache.activemq / activemq-broker 的依赖,以确保 activemq 不会潜入。

添加对 com.ibm.mqjms.jar、com.ibm.mq.jmqi.jar、dhbcore.jar 的依赖

跑步

这些是为 WMQ V5.3 编写的,但大部分仍然适用。 发生变化的更多是关于 WMQ 管理而不是连接和配置。

developerWorks:Spring 系列

请确保在以后的帖子中包含 WMQ 服务器和客户端的版本,因为 Java/JMS 配置的细节不同。 此外,请务必使用与您正在使用的 WMQ 客户端或服务器版本相匹配的文档版本。

您可能还想考虑在 JMS 之上使用 Spring Integration; 这里有一个使用 ActiveMQ 的示例https://github.com/SpringSource/spring-integration-samples/tree/master/basic/jms - 您只需要更改 JMS 配置即可使用 MQ。

从控制台读取的示例通过 JMS 发送消息,由消息驱动的适配器读取,然后写入控制台。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM