Spring JMS and Websphere MQ
Asked Answered
C

4

6

hi I am new to Spring JMS and websphere MQ. Can Any one give me step by step processs or example how to receive message from websphere MQ and be able to print that message in console thanks u very much for your help

Commission answered 25/1, 2013 at 14:14 Comment(1)
I posted a Spring mdp/activation spec/webpshere mq example at #7390786Naval
N
5

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

'

Naval answered 24/2, 2014 at 23:31 Comment(2)
Can you post the pom for your code? I am trying to get this working using Spring STS and having resource exceptions. Posted question here; #32258186Coadjutrix
Where to configure the Queue and QueueManager details?Here only ActiveSpec is configured.How AS will know which queue to connectClamor
C
5

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

Add a bean providing a 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 its way in.

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

Run

Cadaverous answered 26/3, 2017 at 18:35 Comment(0)
H
2

These were written for WMQ V5.3 but mostly still apply. The things that have changed are more about the WMQ admin than the connectivity and config.

developerWorks: The Spring Series

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

Heshvan answered 25/1, 2013 at 14:19 Comment(1)
link doesnt exists anymore :(Zachariah
D
2

You might also want to consider using Spring Integration on top of JMS; there's a sample here that uses ActiveMQ https://github.com/SpringSource/spring-integration-samples/tree/master/basic/jms - you would just need to change the JMS config to use MQ instead.

The sample reads from the console sends the message over JMS, read by a message-driven adapter, and written to the console.

Distrait answered 25/1, 2013 at 15:5 Comment(2)
thanks for the reply and the link . When i downlad it gave me like 20 different project and i cdnt find example needed or neither run it . I just want simple example to be able to runCommission
? confused ? The link points right to the sample on GitHub with a ReadMe about how to run it. Simply clone the Github sample repo and follow the instructions.Distrait

© 2022 - 2024 — McMap. All rights reserved.