【问题标题】:Spring JMS and Websphere MQSpring JMS 和 Websphere MQ
【发布时间】:2013-01-09 12:30:25
【问题描述】:

您好,我是 Spring JMS 和 websphere MQ 的新手。谁能给我一步一步的过程或示例如何从 websphere MQ 接收消息并能够在控制台中打印该消息 非常感谢你的帮助

【问题讨论】:

标签: spring ibm-mq spring-jms


【解决方案1】:

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

developerWorks: The Spring Series

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

【讨论】:

  • 链接不存在了:(
【解决方案2】:

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

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

【讨论】:

  • 感谢您的回复和链接。当我下载它时,它给了我 20 个不同的项目,我找不到需要的示例,或者既不运行它。我只想要简单的示例能够运行
  • ?使困惑 ?该链接直接指向 GitHub 上的示例,其中包含有关如何运行它的自述文件。只需克隆 Github 示例 repo 并按照说明进行操作。
【解决方案3】:

这是一个使用 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);
        }
     }
  }

'

【讨论】:

  • 你可以为你的代码发布 pom 吗?我正在尝试使用 Spring STS 并遇到资源异常来使其正常工作。在这里发布问题; stackoverflow.com/questions/32257686/…
  • 在哪里配置Queue和QueueManager的详细信息?这里只配置了ActiveSpec。AS如何知道连接哪个队列
【解决方案4】:

我自己也经历过。从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 的依赖

运行

【讨论】:

    猜你喜欢
    • 2012-08-27
    • 2016-10-31
    • 2017-01-17
    • 1970-01-01
    • 2017-02-03
    • 1970-01-01
    • 2015-06-19
    • 2019-06-16
    • 2010-10-28
    相关资源
    最近更新 更多