-
1. Re: which parameters 4 jndi lookup?
kabirkhan Feb 26, 2004 7:34 AM (in response to tonig)Not sure I get the question, but here is how we look up a queue from a session bean that places a message on the queue.
InitialContext iniCtx = new InitialContext();
Object tmp = iniCtx.lookup("java:comp/env/jms/QueueConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
m_conn = qcf.createQueueConnection();
m_queue = (Queue) iniCtx.lookup( "java:comp/env/jms/EmSystemEmail");
m_session = m_conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender send = m_session.createSender(m_queue);
ObjectMessage objectMsg = m_session.createObjectMessage(message);
send.send(objectMsg);
send.close();
With a bit of twiddling, you should be able to get it working for topics.
Here are the ejb-jar.xml and jboss.xml entries we use too:
<ejb-name>MailQueueSenderBean</ejb-name>
<local-home>com.exhibitormanual.ejb.mail.sender.MailQueueSenderLocalHome</local-home>
com.exhibitormanual.ejb.mail.sender.MailQueueSenderLocal
<ejb-class>com.exhibitormanual.ejb.mail.sender.MailQueueSenderBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>jms/QueueConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/EmSystemEmail</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
<ejb-name>MailQueueSenderBean</ejb-name>
<jndi-name>ejb/MailQueueSender</jndi-name>
<resource-ref>
<res-ref-name>jms/QueueConnectionFactory</res-ref-name>
<jndi-name>java:/ConnectionFactory</jndi-name>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/EmSystemEmail</resource-env-ref-name>
<jndi-name>queue/EmSystemEmail</jndi-name>
</resource-env-ref> -
2. Re: which parameters 4 jndi lookup?
tonig Feb 26, 2004 7:48 AM (in response to tonig)Thank you, i'll try to get a solution with ur help.
Here is the client am am working at:jndiContext = new InitialContext(System.getProperties()); connectionFactory = (TopicConnectionFactory) jndiContext.lookup("javax.jms.TopicFactory"); connection = connectionFactory.createTopicConnection(); session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) jndiContext.lookup("queue/MyQueue"); sender = session.createPublisher(topic); message = session.createTextMessage("BLAH BLAH BLAH"); sender.publish(message); connection.close();
And here my describtor jboss-service.xml.<?xml version="1.0" encoding="UTF-8"?> <jboss> <enterprise-beans> <message-driven> <display-name>SimpleMessageEJB</display-name> <ejb-name>SimpleMessageEJB</ejb-name> <ejb-class>xample.mdb.SimpleMessageBean</ejb-class> <destination-jndi-name>queue/MyQueue</destination-jndi-name> </message-driven> </enterprise-beans> </jboss>