• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jms configuration in jboss with mysql

 
djyoti sahu
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JMS Setup in JBOSS with mysql:
-------------------
1.Remove hsqldb-jdbc2-service.xml from $JBOSS_HOME/server/default/deploy/jms/ directory
2.Copy $JBOSS_HOME/docs/examples/jms/mysql-jdbc2-service.xml to $JBOSS_HOME/server/default/deploy/jms/
3.Modify name in mysql-jdbc2-service.xml with your name given in mysql-ds.xml (This is in deploy/jms directory)

Ex:in my application name of datasource is myatlasdbpool
<mbean code="org.jboss.mq.pm.jdbc2.PersistenceManager" name="jboss.mq:service=PersistenceManager">
<depends optional-attribute-name="ConnectionManager">jboss.jca:service=LocalTxCM,name=myatlasdbpool</depends>
</mbean>
4.Choose or enter new desitination name in jbossmq-destinations-service.xml (This is in deploy/jms directory)
<mbean code="org.jboss.mq.server.jmx.Queue" name="jboss.mq.destination:service=Queue,name=ex">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
</mbean>
5.Set RecursiveSearch as "True" in jboss-service.xml (This is in default/conf directory)
<attribute name="RecursiveSearch">True</attribute>
6.Make <create-table>true</create-table> in jbosscmp-jdbc.xml config files

<defaults>
<datasource>java:/myatlasdbpool</datasource>
<datasource-mapping>mySQL</datasource-mapping>
<create-table>false</create-table>
<remove-table>false</remove-table>
</defaults>

7.Example Entry in ejb-jar.xml
<message-driven>
<ejb-name>SendMessageMDB</ejb-name>
<ejb-class>com.beo.atlas.beans2.sendmail.SendMessageMDB</ejb-class>
<transaction-type>Container</transaction-type>
<message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
<subscription-durability>NonDurable</subscription-durability>
</message-driven-destination>
</message-driven>
8.Example Entry in jboss.xml, here the prefix "queue/" is a must, we will use this name from the caller
<message-driven>
<ejb-name>SendMessageMDB</ejb-name>
<destination-jndi-name>queue/ex</destination-jndi-name>
</message-driven>
9.Example calling code:

import javax.jms.*;

try {
javax.naming.Context ctx = new InitialContext();
QueueConnectionFactory qcf = (QueueConnectionFactory)ctx.lookup("ConnectionFactory");
QueueConnection qConn = qcf.createQueueConnection();
QueueSession qSession = qConn.createQueueSession(false,1);
Queue q = (Queue) ctx.lookup("queue/ex");
QueueSender sender = qSession.createSender(q);
TextMessage msg = qSession.createTextMessage();
msg.setText("Hello from Shivdeep!");
sender.send(msg);
}
catch(Exception e) {
e.printStackTrace();
}
10.Message Driven Bean: SendMessageMDB.java
import javax.jms.MessageListener;
import javax.ejb.MessageDrivenBean;
import javax.jms.Message;
import javax.ejb.MessageDrivenContext;
public class SendMessageMDB implements MessageDrivenBean, MessageListener {

private MessageDrivenContext ctx;

public void setMessageDrivenContext(MessageDrivenContext ctx) {
this.ctx = ctx;
}
public void ejbCreate() { }
public void ejbRemove() {
ctx = null;
}
public void onMessage(Message msg) {
//THIS CODE WILL BE EXECUTED WHEN THE MESSAGE IS SENT
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic