Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml
xml
borderStylesolid
titlegeronimo-web.xml
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1">

  <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1">

    <dep:moduleId>

      <dep:groupId>org.apache.geronimo.samples</dep:groupId>

      <dep:artifactId>OrderWeb</dep:artifactId>

      <dep:version>1.2</dep:version>

      <dep:type>car</dep:type>

    </dep:moduleId>

    <dep:dependencies>

		<dep:dependency>
			<dep:groupId>org.apache.geronimo.configs</dep:groupId>

			<dep:artifactId>activemq-broker</dep:artifactId>

			<dep:type>car</dep:type>

        </dep:dependency>

		<dep:dependency>

            <dep:groupId>org.apache.geronimo.samples</dep:groupId>

            <dep:artifactId>jms-resources</dep:artifactId>

            <dep:version>1.2</dep:version>

            <dep:type>rar</dep:type>

        </dep:dependency>		

	</dep:dependencies>		

    <dep:hidden-classes/>

    <dep:non-overridable-classes/>

  </dep:environment>



  <context-root>/Order</context-root> 

  <resource-ref>

    <ref-name>jms/CommonConnectionFactory</ref-name>

    <resource-link>CommonConnectionFactory</resource-link>

  </resource-ref>

	

  <resource-env-ref>

	   <ref-name>jms/OrderQueue</ref-name>

	   <admin-object-link>OrderQueue</admin-object-link>

  </resource-env-ref> 

</web-app>

The next important part of this sample application is how to send messages from out side the application server context. Consignment sender will handle it for the application as given below.

Code Block
java
java
borderStylesolid
titleConsignmentSender.java
                        Context ctx = new InitialContext(env);
			
			QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup(propLoader.getValue(CONNECTION_FACTORY_NAMES));
			
			conn = factory.createQueueConnection();
			
			Queue myQueue = (Queue) ctx.lookup(propLoader.getValue(QUEUE_NAME));
			
			session = conn.createQueueSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);

			producer = session.createProducer(myQueue);

			conn.start();
			
			consignmentMessage = session.createTextMessage();	
		
			consignmentMessage.setText(content);
			
			
producer.send(consignmentMessage);
			
			System.out.println("Consignment Sent !!!");

How to listen on a JMS queue other than a MDB? The answer for to this question can be found in the consignment reciever application.

Code Block
java
java
borderStylesolid
titleConsignmentReciever.java
System.out.println("Start Listening Consignment Data ");
			
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(propLoader.getValue(PROVIDER_URL));
			connection = (QueueConnection)connectionFactory.createConnection();
			connection.start();
			
			session = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
			Queue queue = session.createQueue(propLoader.getValue(QUEUE_NAME));
			consumer = session.createConsumer(queue);

			while(true){
				Message message = consumer.receive();
				processMessage(message);
			}

Tools used

The tools used for developing and building the order placement application are:

...

  1. Select Deploy New link from the Console Navigation in the left.
  2. Load the <geronimo_home>/repository/org/apache/geronimo/modules/ge-activemq-rar/1.1.12-beta/ge-activemq-rar-1.1.12-beta.rar file to the Archive field.
  3. Load the Order/config/jms-resource-plan.xml file to the Plan input field.
  4. Press Install button. Make sure Start app after install is selected when this deployment happens
  5. Upon successful installation message, verify the deployment by traversing scrolling down to the JMS resources link. It will display the connection factory and two JMS queues.

...

Code Block
xml
xml
borderStylesolid
titlebuild.properties
## Set the Geronimo 1.12 Home
geronimo.home=/home/lsfkarthi/Projects/LasanthaGeronimo/geronimo-jetty-j2ee-1.1.12-beta

## Set the XDoclet Home 
xdoclet.home=/home/lsfkarthi/Lasanthainstallation/xdoclet-1.2.3

Note

This build script depends on XDoclet version 1.2.3 and Geronimo 1.2.

Code Block
xml
xml
borderStylesolid
titleorder_mgmt.properties
###########################################################

## Order Sender(Web Application) Properties
#  Connection Factory Name. 
jms.connection=java:comp/env/jms/CommonConnectionFactory
# Queue Name.
jms.queue=java:comp/env/jms/OrderQueue

###########################################################

## Order Reciever(EJB Application) Properties
#  Change a directory in server to store order requests. 
order.repo=/home/lsf/Lasantha/Temp/order

###########################################################

## Consignment Sender Properties
#  Queue connection factory type.
java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
#  Server location, change according to your enviroment.
java.naming.provider.url=tcp://localhost:61616
#  Connection factory names.
connectionFactoryNames=CommonConnectionFactory
# Queue name.
queue.ConsignmentQueue=ConsignmentQueue

###########################################################

## Consignment Reciever Properties
#  Provider url, change according to your enviroment.
provider.url=tcp://localhost:61616
# Queue name.
queue.name=ConsignmentQueue
# Change a directory in client machine to store consignment requests.
consignment.dir=/home/lsf/Lasantha/Temp/consignment

...