You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by Eugene Prokopiev <pr...@stc.donpac.ru> on 2006/07/11 12:20:42 UTC

getJMSMessageID on sending message

Hi,

Can I get MessageID after message sending? With this code:

import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnection;

public class Producer {

	public static void main(String[] args) throws Exception {
		
		ActiveMQConnection connection = 
ActiveMQConnection.makeConnection("producer1", "pw1", 
"tcp://ccsk-mobile:61616");
         	connection.start();
         	Session session = connection.createSession(false, 
Session.AUTO_ACKNOWLEDGE);
         	Destination destination = session.createQueue("monitoring.m1");
         	MessageProducer producer = session.createProducer(destination);

         	String text = "Test Message String";
         	TextMessage message = session.createTextMessage(text);
	    	producer.send(session.createTextMessage());
	    	System.out.println("sent message : "+message.getJMSMessageID());

         	session.close();
         	connection.close();
	}

}

I got:

sent message : null

--
Thanks,
Eugene Prokopiev


Re: getJMSMessageID on sending message

Posted by James Strachan <ja...@gmail.com>.
Great catch Hiram - that one had me stumped :)

On 7/11/06, Hiram Chirino <hi...@hiramchirino.com> wrote:
> Your code is creating 2 message instances.  It sends the 2nd one, and the
> prints out the value from the first.
>
> On 7/11/06, Eugene Prokopiev <pr...@stc.donpac.ru> wrote:
> >
> > Hi,
> >
> > Can I get MessageID after message sending? With this code:
> >
> > import javax.jms.Destination;
> > import javax.jms.MessageProducer;
> > import javax.jms.Session;
> > import javax.jms.TextMessage;
> >
> > import org.apache.activemq.ActiveMQConnection;
> >
> > public class Producer {
> >
> >         public static void main(String[] args) throws Exception {
> >
> >                 ActiveMQConnection connection =
> > ActiveMQConnection.makeConnection("producer1", "pw1",
> > "tcp://ccsk-mobile:61616");
> >                 connection.start();
> >                 Session session = connection.createSession(false,
> > Session.AUTO_ACKNOWLEDGE);
> >                 Destination destination = session.createQueue("
> > monitoring.m1");
> >                 MessageProducer producer = session.createProducer
> > (destination);
> >
> >                 String text = "Test Message String";
> >                 TextMessage message = session.createTextMessage(text);
> >                 producer.send(session.createTextMessage());
> >                 System.out.println("sent message :
> > "+message.getJMSMessageID());
> >
> >                 session.close();
> >                 connection.close();
> >         }
> >
> > }
> >
> > I got:
> >
> > sent message : null
> >
> > --
> > Thanks,
> > Eugene Prokopiev
> >
> >
>
>
> --
> Regards,
> Hiram
>
> Blog: http://hiramchirino.com
>
>


-- 

James
-------
http://radio.weblogs.com/0112098/

Re: getJMSMessageID on sending message

Posted by Hiram Chirino <hi...@hiramchirino.com>.
Your code is creating 2 message instances.  It sends the 2nd one, and the
prints out the value from the first.

On 7/11/06, Eugene Prokopiev <pr...@stc.donpac.ru> wrote:
>
> Hi,
>
> Can I get MessageID after message sending? With this code:
>
> import javax.jms.Destination;
> import javax.jms.MessageProducer;
> import javax.jms.Session;
> import javax.jms.TextMessage;
>
> import org.apache.activemq.ActiveMQConnection;
>
> public class Producer {
>
>         public static void main(String[] args) throws Exception {
>
>                 ActiveMQConnection connection =
> ActiveMQConnection.makeConnection("producer1", "pw1",
> "tcp://ccsk-mobile:61616");
>                 connection.start();
>                 Session session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>                 Destination destination = session.createQueue("
> monitoring.m1");
>                 MessageProducer producer = session.createProducer
> (destination);
>
>                 String text = "Test Message String";
>                 TextMessage message = session.createTextMessage(text);
>                 producer.send(session.createTextMessage());
>                 System.out.println("sent message :
> "+message.getJMSMessageID());
>
>                 session.close();
>                 connection.close();
>         }
>
> }
>
> I got:
>
> sent message : null
>
> --
> Thanks,
> Eugene Prokopiev
>
>


-- 
Regards,
Hiram

Blog: http://hiramchirino.com