activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From SuoNayi <suonayi2...@163.com>
Subject Reply:ActiveMQ Stream Messaging & JMS Properties
Date Wed, 02 Jan 2013 13:50:10 GMT
You shoud not call the receive method of ActiveMQInputStream or it will 
cause the data you recevied is one part of the whole.The lost part is the 
payload of the ActiveMQMessage the call of the receive method returns.
Using the getJMSProperties method is the right way.
I found that every message created by producer is reserving the properties 
and this approach is inefficient.Reserving the properties by the first message
is more reasonable. 
You may detail which version you're using.

At 2013-01-01 23:48:33,gfshaikh <ghulam.shaikh@taxware.com> wrote:
>Hi All
>
>I am trying to transfer a large file over ActiveMQ using JMS Streams - the
>transfer works fine however along with the file contents I also need to send
>the file name to the recipient stream - I am trying the following code but
>don't see the data appearing at the recipient end - saw several posts on the
>same topic but none of the solutions work. Would appreciate a quick response
>if someone has a working version of this scenario.
>
>Sender
>-------
>FileInputStream in = new FileInputStream("C:\\InputFile.txt");
>
>    String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
>    ActiveMQConnectionFactory connectionFactory = new
>ActiveMQConnectionFactory(
>      brokerURI);
>    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory
>      .createConnection();
>    connection.start();
>    Session session = connection.createSession(false,
>Session.AUTO_ACKNOWLEDGE);
>    Queue destination = session.createQueue(QUEUE_NAME);
>    Map<String, Object> properties = new HashMap<String, Object>(1);
>    properties.put("testValue", "testValue");
>
>    OutputStream out =
>     
>((ActiveMQConnection)connectionFactory.createConnection()).createOutputStream(destination,
>        properties, ActiveMQMessage.DEFAULT_DELIVERY_MODE,
>        ActiveMQMessage.DEFAULT_PRIORITY,
>ActiveMQMessage.DEFAULT_TIME_TO_LIVE);
>
>byte[] buffer = new byte[1024];
>    while (true)
>    {
>      int bytesRead = in.read(buffer);
>      if (bytesRead == -1)
>      {
>        break;
>      }
>      out.write(buffer, 0, bytesRead);
>    }
>    out.flush();
>    out.close();
>
>Receiver
>---------
>FileOutputStream out = new FileOutputStream(
>      "C:\\ReceivedFile.txt");
>
>    String brokerURI = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
>    ActiveMQConnectionFactory connectionFactory = new
>ActiveMQConnectionFactory(
>      brokerURI);
>    ActiveMQConnection connection = (ActiveMQConnection) connectionFactory
>      .createConnection();
>    connection.start();
>    Session session = connection.createSession(false,
>Session.AUTO_ACKNOWLEDGE);
>    // we want be be an exclusive consumer
>    String exclusiveQueueName = QUEUE_NAME + "?consumer.exclusive=true";
>    Queue destination = session.createQueue(exclusiveQueueName);
>    InputStream in = connection.createInputStream(destination);
>
>    ActiveMQInputStream aqInStream = (ActiveMQInputStream) in;
>    ActiveMQMessage mqMessage = aqInStream.receive();
>    System.out.println(mqMessage.getProperty("testValue"));
>    System.out.println(aqInStream.getJMSProperties());
>    
>    // now write the file from ActiveMQ
>    byte[] buffer = new byte[1024];
>    while (true)
>    {
>      int bytesRead = in.read(buffer);
>      if (bytesRead == -1)
>      {
>        break;
>      }
>      out.write(buffer, 0, bytesRead);
>    }
>    out.close();
>
>
>
>--
>View this message in context: http://activemq.2283324.n4.nabble.com/ActiveMQ-Stream-Messaging-JMS-Properties-tp4661193.html
>Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message