[jboss-user] [JBoss Messaging] - How to send message to a remote queue

Wayland do-not-reply at jboss.com
Thu Nov 20 04:15:13 EST 2008


@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class JMSSender {
	@Resource(mappedName="/queue/myQueue")
	private Queue queue;

	@Resource(mappedName="QueueConnectionFactory")
	private QueueConnectionFactory conFac;

	public void send(final String... msgsTxt) {

		Connection connection = null;
		Session session = null;
		try {
				connection = this.conFac.createConnection();
	      session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); // tx will be commited by container...
	      for (String txt: msgsTxt) {
	      	if (txt != null) {
			      TextMessage msg = session.createTextMessage();
			      msg.setText(txt);      
			      MessageProducer producer = session.createProducer(queue);
			      producer.send(msg);
	      	}
	      }
		}
		catch (JMSException ex) {
			throw new RuntimeException(ex);
		}finally{
			if(session != null){
				try{
					session.close();
				}catch(Exception ignored){}
			}			
			if(connection != null){
				try{
					connection.close();
				}catch(Exception ignored){}
			}
		}
	}
}

The code above has no problem to send message to a local queue.
How can I modify it or configure to make it to send to a remote queue?

change the annotation 
@Resource(mappedName="/queue/myQueue")   to
@Resource(mappedName="jnp://remotehost:1099/queue/myQueue")
seems not work.

If I don't inject the connectionfactory and queue but using remote jndi lookup, it is okay to send the messages but session.commit() needed to be called after sending. (otherwise, the message is not sent)
That's not what I want as it should be container managed. 
How to send the message to remote queue in the container managed transaction? Thanks.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190780#4190780

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4190780



More information about the jboss-user mailing list