Spring JMS and Websphere MQ

hi I am new to Spring JMS and websphere MQ. Can anyone give me step by step processes or an example of how to receive a message from websphere MQ and be able to print that message to the console thank you very much for your help

+3


source to share


4 answers


Here is a working example using 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);
        }
     }
  }

      

+4


source


They were written for WMQ V5.3, but are still mostly used. All that has changed has more to do with the WMQ admin than connectivity and configuration.

developerWorks: Spring Series



Please remember to include the WMQ server and client versions in future posts, as Java / JMS configuration details differ. Also, be sure to use the version of the documentation that matches the version of the WMQ client or server you are working with.

+2


source


You can also consider using Spring integration over JMS; there is a sample here that uses ActiveMQ https://github.com/SpringSource/spring-integration-samples/tree/master/basic/jms - you just need to change your JMS config to use MQ instead.

A sample read from the console sends a message via JMS, is read by the message-driven adapter, and written to the console.

+2


source


I just went through it myself. Start with Spring Boot JMS Starter

Add bean by providing MQQueueConnectionFactory

@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;
    }
}

      

Remove the dependency on org.apache.activemq / activemq-broker to make sure activemq doesn't sneak in.

Add dependencies on com.ibm.mqjms.jar, com.bim.mq.jmqi.jar, dhbcore.jar

Run

+2


source







All Articles