activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gfshaikh <ghulam.sha...@taxware.com>
Subject ActiveMQ Stream Messaging & JMS Properties
Date Tue, 01 Jan 2013 15:48:33 GMT
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
View raw message