Versions Compared

Key

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

...

  1. Right click under project explorer and Select New-> Project-> EJB Project.





  2. Name the project as MessageDrivenBean and Select Next.





  3. On the next screen keep defaults and select Next.





  4. On the next screen uncheck Generate Deployment Descriptor and select Next.





  5. Next screen suggests to configure Geronimo Deployment Plan. For current tutorial we are keeping the default values.





    This creates the skeleton of the EJB project. Next step is to add a pojo to our project and annotate it.
  6. Right click on EJB project and select New->class.





  7. Name the class as AdminMDB and package as mdb. Select Finish.





  8. Add the following code to AdminMDB.java.
    Code Block
    titleAdminMDB.java
    borderStylesolid
    
    package mdb;
    
    import javax.ejb.ActivationConfigProperty;
    import javax.ejb.MessageDriven;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.TextMessage;
    
    @MessageDriven(
    name="Admin",
    activationConfig = {
    @ActivationConfigProperty(
    propertyName="destinationType",
    propertyValue="javax.jms.Queue"),
    @ActivationConfigProperty(
    propertyName="destinationName",
    propertyValue="jms/TestQueue")
    }
    )
    public class AdminMDB implements MessageListener {
    
    public void onMessage(Message msg) {
    	
    	if (msg instanceof TextMessage) {
    		   TextMessage tm = (TextMessage) msg;
    		   try {
    		    System.out.println("Received new message");
    		    System.out.println("CustomerId : " +tm.getStringProperty("username"));
    		    System.out.println("CustomerName : " +tm.getStringProperty("userid"));
    		    System.out.println("Old Address : " +tm.getStringProperty("oldaddress"));
    		    System.out.println("New Address : " +tm.getStringProperty("newaddress") );
    		   } catch (JMSException e) {
    		      e.printStackTrace();
    		   }
    	
    	 
    }
    }
    }
    

Modifying Deployment plan

  1. In WebMDB project select WebContent/WEB-INF/geronimo-web.xml and modify the content with the one shown below.
    Code Block
    titlegeronimo-web.xml
    borderStylesolid
    
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.2" 
             xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2" 
             xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" 
             xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
        <sys:environment>
            <sys:moduleId>
                <sys:groupId>default</sys:groupId>
                <sys:artifactId>WebMDB</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>car</sys:type>
            </sys:moduleId>
            <sys:dependencies>
                <sys:dependency>
                    <sys:groupId>default</sys:groupId>
                    <sys:artifactId>MessageDrivenBean</sys:artifactId>
                    <sys:version>1.0</sys:version>
                    <sys:type>car</sys:type>
                </sys:dependency>
                <sys:dependency>
                    <sys:groupId>org.apache.geronimo.configs</sys:groupId>
                    <sys:artifactId>activemq-ra</sys:artifactId>
                    <sys:version>2.1</sys:version>
                    <sys:type>car</sys:type>
                </sys:dependency>
            </sys:dependencies>
        </sys:environment>
        <context-root>/WebMDB</context-root>
        <nam:resource-ref>
            <nam:ref-name>jms/TestConnectionFactory</nam:ref-name>
            <nam:pattern>
                <nam:groupId>org.apache.geronimo.configs</nam:groupId>
                <nam:artifactId>activemq-ra</nam:artifactId>
                <nam:version>2.1</nam:version>
                <nam:name>DefaultActiveMQConnectionFactory</nam:name>
            </nam:pattern>
        </nam:resource-ref>
        <nam:resource-env-ref>
            <nam:ref-name>jms/TestQueue</nam:ref-name>
            <nam:pattern>
                <nam:groupId>org.apache.geronimo.configs</nam:groupId>
                <nam:artifactId>activemq-ra</nam:artifactId>
                <nam:version>2.1</nam:version>
                <nam:name>SendReceiveQueue</nam:name>
            </nam:pattern>
        </nam:resource-env-ref>
    </web-app>