Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New Spring based WebsphereMQ quickstart #356

Closed
wants to merge 1 commit into from

2 participants

@doug-grove

hope for the best

@sgilda
Owner

There is a discussion on the jdf-list about whether this quickstart belongs here due do the need to purchase 3rd party software, complexity of configuration, and support issues.

@sgilda
Owner

Based on the feedback, I don't think this quickstart belongs here. It would probably be better as a GSS quickstart. Closing the pull.

@sgilda sgilda closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 12, 2012
  1. @doug-grove
This page is out of date. Refresh to see the latest.
View
111 spring-webspheremq/README.md
@@ -0,0 +1,111 @@
+spring-websphere-mq: Using IBM WebSphere MQ and Spring with JBoss EAP 6
+======================================================
+Author: Doug Grove
+Level: Intermediate
+Technologies: JMS, Spring
+Summary: Spring Message Driven POJOs with IBM MQ Messaging
+Prerequisites: none
+Target Product: EAP
+
+
+What is it?
+-----------
+
+This quickstart demonstrates deploying IBM's MQ messaging product and integration with Spring JMS. The sample contains configurations
+for both in-bound and out-bound messaging.
+
+The out-bound messaging components are defined in the JBoss application servers XML configuration file. An example section is
+provided in the src/test/resources folder. This example configures the logging for IBM MQ and both a queue and a connection factory
+that are later used for out-bound messaging. Change the host names, port and queue names as needed.
+
+The IBM MQ Resource Adapter (wmq.jmsra.rar) needs to be deployed. The Resource Adapter can be deployed from the WebUI.
+
+Note that there needs to be an entry in the MANIFEST.MF indicating that the IBM MQ Resource Adapter is needed by this applicaction. This
+is:
+
+Dependencies: deployment.wmq.jmsra.rar
+
+without this entry in the MANIFEST.MF file, the Resource Adapter will not be loaded and the classes in the adapter will not be found. This
+entry is configured the pom.xml file in the maven-war-plugin configuration.
+
+The in-bound, message driven, components are configured in the Spring application context file. This is the applicationContextServices.xml
+file located in the src/main/resources folder.
+
+When ran, a messages placed on the in-bound message queue is delivered to the Message Driven POJO. This class, in the onMessage() method,
+then resends the message to the out-bound message queue.
+
+
+System requirements
+-------------------
+
+All you need to build this project is Java 6.0 (Java SDK 1.6) or better, Maven 3.0 or better.
+
+The application this project produces is designed to be run on JBoss Enterprise Application Platform 6 or JBoss AS 7.
+
+
+Configure Maven
+---------------
+
+If you have not yet done so, you must [Configure Maven](../README.md#mavenconfiguration) before testing the quickstarts.
+
+
+Configure Optional Components
+-------------------------
+
+ * This quickstart uses IBM WebSphere MQ messaging. It requires that the IBM MQ Resource Adapter is deployed to the application server. The configuration
+files will need to be changed to match the messaging servers deployment. Note that where queue names are in all-caps that these are the queue names as
+defined on the IBM MQ product.
+
+
+Start JBoss Enterprise Application Platform 6 or JBoss AS 7 with the Web Profile
+-------------------------
+
+1. Open a command line and navigate to the root of the JBoss server directory.
+2. The following shows the command line to start the server with the web profile:
+
+ For Linux: JBOSS_HOME/bin/standalone.sh
+ For Windows: JBOSS_HOME\bin\standalone.bat
+
+
+Build and Deploy the Quickstart
+-------------------------
+
+_NOTE: The following build command assumes you have configured your Maven user settings. If you have not, you must include Maven setting arguments on the command line. See [Build and Deploy the Quickstarts](../README.md#buildanddeploy) for complete instructions and additional options._
+
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. Type this command to build and deploy the archive:
+
+ mvn clean package jboss-as:deploy
+
+4. This will deploy `target/jboss-as-spring-websphere-mq.war` to the running instance of the server.
+
+
+Undeploy the Archive
+--------------------
+
+Contributor: For example:
+
+1. Make sure you have started the JBoss Server as described above.
+2. Open a command line and navigate to the root directory of this quickstart.
+3. When you are finished testing, type this command to undeploy the archive:
+
+ mvn jboss-as:undeploy
+
+
+Run the Quickstart in JBoss Developer Studio or Eclipse
+-------------------------------------
+
+You can also start the server and deploy the quickstarts from Eclipse using JBoss tools. For more information, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](../README.md#useeclipse)
+
+
+Debug the Application
+------------------------------------
+
+Contributor: For example:
+
+If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
+
+ mvn dependency:sources
+ mvn dependency:resolve -Dclassifier=javadoc
+
View
144 spring-webspheremq/pom.xml
@@ -0,0 +1,144 @@
+<?xml version="1.0"?>
+<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc.
+ and/or its affiliates, and individual contributors by the @authors tag. See
+ the copyright.txt in the distribution for a full listing of individual contributors.
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ use this file except in compliance with the License. You may obtain a copy
+ of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.as.quickstarts</groupId>
+ <artifactId>jboss-as-spring-websphere-mq</artifactId>
+ <version>7.1.2-SNAPSHOT</version>
+ <packaging>war</packaging>
+ <name>JBoss AS Quickstarts: Spring and IBM WebSphere MQ</name>
+ <description>Spring and IBM MQ: A sample project demonstrating IBM MQ and Spring Integration</description>
+
+ <url>http://jboss.org/jbossas</url>
+ <licenses>
+ <license>
+ <name>Apache License, Version 2.0</name>
+ <distribution>repo</distribution>
+ <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
+ </license>
+ </licenses>
+
+ <properties>
+ <!-- Explicitly declaring the source encoding eliminates the following
+ message: -->
+ <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
+ resources, i.e. build is platform dependent! -->
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <!-- JBoss dependency versions -->
+ <version.org.jboss.as>7.1.2.Final</version.org.jboss.as>
+ <version.org.jboss.as.plugins.maven.plugin>7.3.Final</version.org.jboss.as.plugins.maven.plugin>
+ <version.org.jboss.spec.jboss.javaee.6.0>3.0.0.Final</version.org.jboss.spec.jboss.javaee.6.0>
+
+ <!-- other plugin versions -->
+ <version.compiler.plugin>2.3.1</version.compiler.plugin>
+ <version.war.plugin>2.1.1</version.war.plugin>
+
+ <!-- maven-compiler-plugin -->
+ <maven.compiler.target>1.6</maven.compiler.target>
+ <maven.compiler.source>1.6</maven.compiler.source>
+
+ <!-- Spring version -->
+ <spring.version>3.1.3.RELEASE</spring.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Define the version of JBoss' Java EE 6 APIs we want to import. Any
+ dependencies from org.jboss.spec will have their version defined by this
+ BOM -->
+ <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
+ of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
+ of artifacts. We use this here so that we always get the correct versions
+ of artifacts. Here we use the jboss-javaee-6.0 stack (you can read this as
+ the JBoss stack of the Java EE 6 APIs). You can actually use this stack with
+ any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
+ <dependency>
+ <groupId>org.jboss.spec</groupId>
+ <artifactId>jboss-javaee-6.0</artifactId>
+ <version>${version.org.jboss.spec.jboss.javaee.6.0}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- JMS API -->
+ <dependency>
+ <groupId>org.jboss.spec.javax.jms</groupId>
+ <artifactId>jboss-jms-api_1.1_spec</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging</artifactId>
+ <version>3.1.1.GA</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Spring JMS -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jms</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <!-- Spring Web loading Spring from a WAR file, configuring via web.xml -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <!-- Set the name of the war, used as the context root when the app is deployed -->
+ <finalName>${project.artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>${version.war.plugin}</version>
+ <configuration>
+ <!-- stop mangling jar names with versions.... -->
+ <outputFileNameMapping>@{artifactId}@.@{extension}@</outputFileNameMapping>
+ <archive>
+ <manifestEntries>
+ <!-- IMPORTANT - import the IBM MQ Resource Adapter -->
+ <!-- Failing to import the Resource Adapter leads to NoClassDef found exceptions -->
+ <Dependencies>deployment.wmq.jmsra.rar</Dependencies>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <!-- JBoss AS plugin to deploy war -->
+ <plugin>
+ <groupId>org.jboss.as.plugins</groupId>
+ <artifactId>jboss-as-maven-plugin</artifactId>
+ <version>${version.org.jboss.as.plugins.maven.plugin}</version>
+ </plugin>
+ <!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation processors -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${version.compiler.plugin}</version>
+ <configuration>
+ <source>${maven.compiler.source}</source>
+ <target>${maven.compiler.target}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
View
89 spring-webspheremq/src/main/java/org/jboss/as/quickstarts/spring_mq/MessageDrivenPOJO.java
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.as.quickstarts.spring_mq;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.jboss.logging.Logger;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.core.MessageCreator;
+
+/**
+ * A Spring Message Driven POJO
+ *
+ * @author dgrove
+ *
+ */
+public class MessageDrivenPOJO implements MessageListener {
+ /** Logger for the class. */
+ private static final Logger logger = Logger.getLogger(MessageDrivenPOJO.class);
+
+ /** Spring messaging template */
+ private JmsTemplate jmsTemplate;
+ private Queue queue;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
+ */
+ @Override
+ public void onMessage(Message message) {
+ logger.info("Entering onMessage");
+
+ if (message instanceof TextMessage) {
+ try {
+ final String text = ((TextMessage) message).getText();
+ // print the message
+ logger.info(text);
+
+ // re-send the message
+ this.jmsTemplate.send(this.queue, new MessageCreator() {
+ public Message createMessage(Session session) throws JMSException {
+ return session.createTextMessage(text);
+ }
+ });
+ } catch (JMSException e) {
+ logger.error(e);
+ }
+ }
+ }
+
+ /**
+ * Injected from the Spring Context
+ *
+ * @param queue
+ */
+ public void setQueue(Queue queue) {
+ this.queue = queue;
+ }
+
+ /**
+ * Injected from the Spring Context
+ *
+ * @param cf
+ */
+ public void setConnectionFactory(ConnectionFactory cf) {
+ this.jmsTemplate = new JmsTemplate(cf);
+ }
+}
View
85 spring-webspheremq/src/main/resources/applicationContextServices.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
+ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:jms="http://www.springframework.org/schema/jms"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/jms http://www.springframework.org/schema/context/spring-jms-3.0.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
+
+ <!-- enable annotations -->
+ <context:annotation-config />
+
+ <!-- process annotated beans -->
+ <bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
+
+ <!-- ************************************** -->
+ <!-- Out-bound Connection Factory and Queue -->
+ <!-- ************************************** -->
+
+ <!-- a IBM MQ queue from JNDI -->
+ <bean id="mqSendQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
+ <property name="jndiName">
+ <value>java:jboss/mqGSS</value>
+ </property>
+ </bean>
+
+ <!-- a IBM MQ Connection Factory from JNDI -->
+ <bean id="mqSendConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
+ <property name="jndiName">
+ <value>java:jboss/mqConnectionFactory</value>
+ </property>
+ </bean>
+
+ <!-- *********************************** -->
+ <!-- In-bound Message Driven Components -->
+ <!-- *********************************** -->
+
+ <!-- this is the Message Driven POJO (MDP) -->
+ <bean id="messageDrivenPOJO" class="org.jboss.as.quickstarts.spring_mq.MessageDrivenPOJO">
+ <!-- provide the two components for out bound messaging -->
+ <property name="queue" ref="mqSendQueue" />
+ <property name="connectionFactory" ref="mqSendConnectionFactory" />
+ </bean>
+
+ <!-- The IBM MQ Resource Adapter -->
+ <bean id="mqResourceAdapter"
+ class="org.springframework.jca.support.ResourceAdapterFactoryBean">
+ <property name="resourceAdapter">
+ <bean class="com.ibm.mq.connector.ResourceAdapterImpl">
+ <property name="connectionConcurrency" value="5" />
+ <property name="maxConnections" value="10" />
+ </bean>
+ </property>
+ <property name="workManager">
+ <bean class="org.springframework.jca.work.SimpleTaskWorkManager" />
+ </property>
+ </bean>
+
+ <!-- Configure the messaging end point -->
+ <bean
+ class="org.springframework.jms.listener.endpoint.JmsMessageEndpointManager">
+ <property name="resourceAdapter" ref="mqResourceAdapter" />
+ <property name="activationSpec">
+ <bean class="com.ibm.mq.connector.inbound.ActivationSpecImpl">
+ <!-- do not use JNDI - use names as specified in IBM MQ -->
+ <property name="useJNDI" value="false" />
+ <!-- queue name as defined in IBM MQ -->
+ <property name="destination" value="GSS.QUEUE" />
+ <property name="destinationType" value="javax.jms.Queue" />
+ <property name="hostName" value="10.0.0.124" />
+ <property name="port" value="1414" />
+ <property name="channel" value="SYSTEM.DEF.SVRCONN" />
+ <property name="transportType" value="CLIENT" />
+<!-- as needed
+ <property name="username" value="testUser"/>
+ <property name="password" value="testPassword"/>
+-->
+ </bean>
+ </property>
+ <property name="messageListener" ref="messageDrivenPOJO" />
+ </bean>
+</beans>
View
18 spring-webspheremq/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <display-name>SpringWAR</display-name>
+
+ <!-- Spring Configuration File -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>classpath:/applicationContextServices.xml</param-value>
+ </context-param>
+
+ <!-- Spring Context Loader Listener -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+</web-app>
View
51 spring-webspheremq/src/test/resources/mq-resources.xml
@@ -0,0 +1,51 @@
+<!--
+The resource-adapter configuration used for this sample, change as needed, add to your server configuration file:
+
+Note that the resource adapter logging is configured here. Also, "username" and "password" can be added to
+the connection-definition section as config-property entries.
+-->
+ <subsystem xmlns="urn:jboss:domain:resource-adapters:1.0">
+ <resource-adapters>
+ <resource-adapter>
+ <archive>
+ wmq.jmsra.rar
+ </archive>
+ <transaction-support>NoTransaction</transaction-support>
+ <config-property name="traceLevel">
+ 6
+ </config-property>
+ <config-property name="traceEnabled">
+ true
+ </config-property>
+ <config-property name="traceDestination">
+ System.out
+ </config-property>
+ <connection-definitions>
+ <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:jboss/mqConnectionFactory" pool-name="mqConnectionFactory">
+ <config-property name="port">
+ 1414
+ </config-property>
+ <config-property name="hostName">
+ 10.0.0.124
+ </config-property>
+ <config-property name="channel">
+ SYSTEM.DEF.SVRCONN
+ </config-property>
+ <config-property name="transportType">
+ CLIENT
+ </config-property>
+ <config-property name="queueManager">
+ redhat.queue.manager
+ </config-property>
+ </connection-definition>
+ </connection-definitions>
+ <admin-objects>
+ <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/mqGSS" pool-name="mqGSS">
+ <config-property name="baseQueueName">
+ GSS.BRIDGE.QUEUE
+ </config-property>
+ </admin-object>
+ </admin-objects>
+ </resource-adapter>
+ </resource-adapters>
+ </subsystem>
Something went wrong with that request. Please try again.