users@glassfish.java.net

RE: Help me Im dying with jms

From: Markus Karg <karg_at_quipsy.de>
Date: Fri, 27 Jun 2008 20:32:50 +0200

Hi,

this code is working pretty well in one of my session beans:

@Resource(mappedName = "MY_CONNECTION_FACTORY")
private ConnectionFactory connectionFactory;

@Resource(mappedName = "MY_TOPIC")
private Destination destination;

Connection connection = this.connectionFactory.createConnection();
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(this.destination);
Message message = session.createObjectMessage(messageObject);
message.setJMSType("MY_TYPE");
message.setStringProperty("MY_PROPERTY", "MY_VALUE");
producer.send(message, deliveryMode, priority, timeToLive);
producer.close();
session.close();
connection.close();

MY_CONNECTION_FACTORY and MY_TOPIC are the JNDI names that you provided in the GlassFish Admin Console when you created the JMS resources.

If you want to use that in a client instead of a session bean, then the annotated members must be declared static. Alternatively you can use JNDI to lookup the resources manually. In that case, there is no need for 'static'. Also, if you do not use the Application Client Container, you cannot use @Resource but then you must use JNDI always.

HTH
Markus

-----Original Message-----
From: glassfish_at_javadesktop.org [mailto:glassfish_at_javadesktop.org]
Sent: Freitag, 27. Juni 2008 20:21
To: users_at_glassfish.dev.java.net
Subject: Help me Im dying with jms

I want to write a stand alone java application that writes a message to a connection factory i used admin console to create. Could someone post some a sample code of this because I have tried everything. Would i use http://localhost
mq:localhost
Please help me out.
[Message sent by forum member 'kenbarnesjr' (kenbarnesjr)]

http://forums.java.net/jive/thread.jspa?messageID=283024

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net