Java Code Examples for javax.jms.Session#createStreamMessage()

The following examples show how to use javax.jms.Session#createStreamMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageCompressionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendTestStreamMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);
   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
   connection.close();
}
 
Example 2
Source File: MessageSender.java    From fixflow with Apache License 2.0 6 votes vote down vote up
public void process(Session session,Destination engine) throws Exception {
	        MessageProducer producer = session.createProducer(engine);
	        //通知客户端开始接受文件
	        StreamMessage message = session.createStreamMessage();
	        
	        //开始发送文件
	        byte[] content = new byte[4096];
	        BufferedInputStream bins = new BufferedInputStream(ins);
	        while (bins.read(content) > 0) {
	            message = session.createStreamMessage();
//	            message.clearBody();
	            message.writeBytes(content);
	            producer.send(message);
	        }
	        bins.close();
	        ins.close();
		}
 
Example 3
Source File: JmsProduceMessageTypesTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSendJMSStreamMessage() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    String payload = "TEST";

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    MessageProducer producer = session.createProducer(queue);
    StreamMessage message = session.createStreamMessage();
    message.writeString(payload);
    producer.send(message);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(1, proxy.getQueueSize());

    MessageConsumer consumer = session.createConsumer(queue);
    Message received = consumer.receive(5000);
    assertNotNull(received);
    assertTrue(received instanceof StreamMessage);
    StreamMessage stream = (StreamMessage) received;
    assertEquals(payload, stream.readString());
}
 
Example 4
Source File: JMSMessageTypesTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void testStreamMessageSendReceive(Connection producerConnection, Connection consumerConnection) throws Throwable {
   Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createQueue(getQueueName());

   MessageProducer producer = session.createProducer(queue);
   for (int i = 0; i < NUM_MESSAGES; i++) {
      StreamMessage message = session.createStreamMessage();
      message.writeInt(i);
      message.writeBoolean(true);
      message.writeString("test");
      producer.send(message);
   }

   Session sessionConsumer = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue consumerQueue = sessionConsumer.createQueue(getQueueName());
   final MessageConsumer consumer = sessionConsumer.createConsumer(consumerQueue);

   for (int i = 0; i < NUM_MESSAGES; i++) {
      StreamMessage m = (StreamMessage) consumer.receive(5000);
      Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m);

      Assert.assertEquals(i, m.readInt());
      Assert.assertEquals(true, m.readBoolean());
      Assert.assertEquals("test", m.readString());
   }
}
 
Example 5
Source File: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendStreamMessageUsingOpenWire(String queueName) throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   StreamMessage streamMessage = session.createStreamMessage();
   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 2);
   streamMessage.writeBytes(new byte[]{6, 7});
   streamMessage.writeChar('b');
   streamMessage.writeDouble(6.5);
   streamMessage.writeFloat((float) 93.9);
   streamMessage.writeInt(7657);
   streamMessage.writeLong(239999L);
   streamMessage.writeShort((short) 34222);
   streamMessage.writeString("hello streammessage");

   producer.send(streamMessage);
}
 
Example 6
Source File: CompressedInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendCompressedStreamMessageUsingOpenWire() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   StreamMessage streamMessage = session.createStreamMessage();

   streamMessage.writeBoolean(true);
   streamMessage.writeByte((byte) 10);
   streamMessage.writeBytes(TEXT.getBytes());
   streamMessage.writeChar('A');
   streamMessage.writeDouble(55.3D);
   streamMessage.writeFloat(79.1F);
   streamMessage.writeInt(37);
   streamMessage.writeLong(56652L);
   streamMessage.writeObject(new String("VVVV"));
   streamMessage.writeShort((short) 333);
   streamMessage.writeString(TEXT);

   producer.send(streamMessage);
}
 
Example 7
Source File: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void sendStreamMessageUsingCoreJms(String queueName) throws Exception {
   Connection jmsConn = null;
   try {
      jmsConn = coreCf.createConnection();
      Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      StreamMessage msg = session.createStreamMessage();
      msg.writeBoolean(true);
      msg.writeByte((byte) 2);
      msg.writeBytes(new byte[]{6, 7});
      msg.writeChar('b');
      msg.writeDouble(6.5);
      msg.writeFloat((float) 93.9);
      msg.writeInt(7657);
      msg.writeLong(239999L);
      msg.writeShort((short) 34222);
      msg.writeString("hello streammessage");

      Queue queue = session.createQueue(queueName);
      MessageProducer producer = session.createProducer(queue);

      producer.send(msg);
   } finally {
      if (jmsConn != null) {
         jmsConn.close();
      }
   }

}
 
Example 8
Source File: ActiveMQRASession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Create a stream message
 *
 * @return The message
 * @throws JMSException Thrown if an error occurs
 */
@Override
public StreamMessage createStreamMessage() throws JMSException {
   Session session = getSessionInternal();

   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("createStreamMessage" + session);
   }

   return session.createStreamMessage();
}
 
Example 9
Source File: TestGetJMSQueue.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendStreamToQueue() throws Exception {
    PutJMS putJms = new PutJMS();
    TestRunner putRunner = TestRunners.newTestRunner(putJms);
    putRunner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    putRunner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    putRunner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE);
    putRunner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    putRunner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);
    WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(putRunner.getProcessContext(), true);
    final Session jmsSession = wrappedProducer.getSession();
    final MessageProducer producer = wrappedProducer.getProducer();

    final StreamMessage message = jmsSession.createStreamMessage();
    message.writeBytes("Hello Stream".getBytes());

    producer.send(message);
    jmsSession.commit();

    GetJMSQueue getJmsQueue = new GetJMSQueue();
    TestRunner runner = TestRunners.newTestRunner(getJmsQueue);
    runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    runner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);

    runner.run();

    List<MockFlowFile> flowFiles = runner
            .getFlowFilesForRelationship(new Relationship.Builder().name("success").build());

    assertTrue(flowFiles.size() == 1);
    MockFlowFile successFlowFile = flowFiles.get(0);
    successFlowFile.assertContentEquals("Hello Stream");
    successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");

    producer.close();
    jmsSession.close();
}
 
Example 10
Source File: TestGetJMSQueue.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendStreamToQueue() throws Exception {
    PutJMS putJms = new PutJMS();
    TestRunner putRunner = TestRunners.newTestRunner(putJms);
    putRunner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    putRunner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    putRunner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE);
    putRunner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    putRunner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);
    WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(putRunner.getProcessContext(), true);
    final Session jmsSession = wrappedProducer.getSession();
    final MessageProducer producer = wrappedProducer.getProducer();

    final StreamMessage message = jmsSession.createStreamMessage();
    message.writeBytes("Hello Stream".getBytes());

    producer.send(message);
    jmsSession.commit();

    GetJMSQueue getJmsQueue = new GetJMSQueue();
    TestRunner runner = TestRunners.newTestRunner(getJmsQueue);
    runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER);
    runner.setProperty(JmsProperties.URL, "vm://localhost?broker.persistent=false");
    runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing");
    runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO);

    runner.run();

    List<MockFlowFile> flowFiles = runner
            .getFlowFilesForRelationship(new Relationship.Builder().name("success").build());

    assertTrue(flowFiles.size() == 1);
    MockFlowFile successFlowFile = flowFiles.get(0);
    successFlowFile.assertContentEquals("Hello Stream");
    successFlowFile.assertAttributeEquals("jms.JMSDestination", "queue.testing");

    producer.close();
    jmsSession.close();
}
 
Example 11
Source File: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompression() throws Exception {

   Connection cconnection = null;
   Connection connection = null;
   try {
      ActiveMQConnectionFactory cfactory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "");
      cconnection = cfactory.createConnection();
      cconnection.start();
      Session csession = cconnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue cQueue = csession.createQueue(queueName);
      MessageConsumer consumer = csession.createConsumer(cQueue);

      ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://" + OWHOST + ":" + OWPORT + "?jms.useCompression=true");
      connection = factory.createConnection();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(queueName);

      MessageProducer producer = session.createProducer(queue);
      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

      //text
      TextMessage textMessage = session.createTextMessage();
      textMessage.setText(testString);
      TextMessage receivedMessage = sendAndReceive(textMessage, producer, consumer);

      String receivedText = receivedMessage.getText();
      assertEquals(testString, receivedText);

      //MapMessage
      MapMessage mapMessage = session.createMapMessage();
      mapMessage.setString(testProp, propValue);
      MapMessage receivedMapMessage = sendAndReceive(mapMessage, producer, consumer);
      String value = receivedMapMessage.getString(testProp);
      assertEquals(propValue, value);

      //Object
      ObjectMessage objMessage = session.createObjectMessage();
      objMessage.setObject(testString);
      ObjectMessage receivedObjMessage = sendAndReceive(objMessage, producer, consumer);
      String receivedObj = (String) receivedObjMessage.getObject();
      assertEquals(testString, receivedObj);

      //Stream
      StreamMessage streamMessage = session.createStreamMessage();
      streamMessage.writeString(testString);
      StreamMessage receivedStreamMessage = sendAndReceive(streamMessage, producer, consumer);
      String streamValue = receivedStreamMessage.readString();
      assertEquals(testString, streamValue);

      //byte
      BytesMessage byteMessage = session.createBytesMessage();
      byte[] bytes = testString.getBytes();
      byteMessage.writeBytes(bytes);

      BytesMessage receivedByteMessage = sendAndReceive(byteMessage, producer, consumer);
      long receivedBodylength = receivedByteMessage.getBodyLength();

      assertEquals("bodylength Correct", bytes.length, receivedBodylength);

      byte[] receivedBytes = new byte[(int) receivedBodylength];
      receivedByteMessage.readBytes(receivedBytes);

      String receivedString = new String(receivedBytes);
      assertEquals(testString, receivedString);

      //Message
      Message m = session.createMessage();
      sendAndReceive(m, producer, consumer);
   } finally {
      if (cconnection != null) {
         connection.close();
      }
      if (connection != null) {
         cconnection.close();
      }
   }

}
 
Example 12
Source File: PutJMS.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
private Message createMessage(final Session jmsSession, final ProcessContext context, final byte[] messageContent,
        final FlowFile flowFile, final Destination replyToQueue, final Integer priority) throws JMSException {
    final Message message;

    switch (context.getProperty(MESSAGE_TYPE).getValue()) {
        case MSG_TYPE_EMPTY: {
            message = jmsSession.createTextMessage("");
            break;
        }
        case MSG_TYPE_STREAM: {
            final StreamMessage streamMessage = jmsSession.createStreamMessage();
            streamMessage.writeBytes(messageContent);
            message = streamMessage;
            break;
        }
        case MSG_TYPE_TEXT: {
            message = jmsSession.createTextMessage(new String(messageContent, UTF8));
            break;
        }
        case MSG_TYPE_MAP: {
            message = jmsSession.createMapMessage();
            break;
        }
        case MSG_TYPE_BYTE:
        default: {
            final BytesMessage bytesMessage = jmsSession.createBytesMessage();
            bytesMessage.writeBytes(messageContent);
            message = bytesMessage;
        }
    }

    message.setJMSTimestamp(System.currentTimeMillis());

    if (replyToQueue != null) {
        message.setJMSReplyTo(replyToQueue);
    }

    if (priority != null) {
        message.setJMSPriority(priority);
    }

    if (context.getProperty(ATTRIBUTES_TO_JMS_PROPS).asBoolean()) {
        copyAttributesToJmsProps(flowFile, message);
    }

    return message;
}
 
Example 13
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testPersistedMessageType() throws Exception {
   Connection theConn = null;
   Connection theOtherConn = null;

   try {
      theConn = createConnection();
      theConn.start();

      // Send some persistent messages to a queue with no receivers
      Session sessSend = theConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageProducer theProducer = sessSend.createProducer(queue1);
      theProducer.setDeliveryMode(DeliveryMode.PERSISTENT);

      Message m = sessSend.createMessage();
      m.setStringProperty("p1", "aardvark");

      BytesMessage bm = sessSend.createBytesMessage();
      bm.writeObject("aardvark");

      MapMessage mm = sessSend.createMapMessage();
      mm.setString("s1", "aardvark");

      ObjectMessage om = sessSend.createObjectMessage();
      om.setObject("aardvark");

      StreamMessage sm = sessSend.createStreamMessage();
      sm.writeString("aardvark");

      TextMessage tm = sessSend.createTextMessage("aardvark");

      theProducer.send(m);
      theProducer.send(bm);
      theProducer.send(mm);
      theProducer.send(om);
      theProducer.send(sm);
      theProducer.send(tm);

      theConn.close();

      theOtherConn = createConnection();
      theOtherConn.start();

      Session sessReceive = theOtherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer theConsumer = sessReceive.createConsumer(queue1);

      Message m2 = theConsumer.receive(1500);

      log.trace("m2 is " + m2);

      ProxyAssertSupport.assertNotNull(m2);

      ProxyAssertSupport.assertEquals("aardvark", m2.getStringProperty("p1"));

      BytesMessage bm2 = (BytesMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", bm2.readUTF());

      MapMessage mm2 = (MapMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", mm2.getString("s1"));

      ObjectMessage om2 = (ObjectMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", (String) om2.getObject());

      StreamMessage sm2 = (StreamMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", sm2.readString());

      TextMessage tm2 = (TextMessage) theConsumer.receive(1500);
      ProxyAssertSupport.assertEquals("aardvark", tm2.getText());
   } finally {
      if (theConn != null) {
         theConn.close();
      }
      if (theOtherConn != null) {
         theOtherConn.close();
      }
   }
}
 
Example 14
Source File: StreamMessageIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testSentStreamMessageIsReadOnly() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue("myQueue");
        MessageProducer producer = session.createProducer(queue);

        String myString = "myString";

        // Prepare a StreamMessage to send to the test peer to send
        StreamMessage streamMessage = session.createStreamMessage();

        streamMessage.writeString(myString);

        // prepare a matcher for the test peer to use to receive and verify the message
        List<Object> list = new ArrayList<Object>();
        list.add(myString);

        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        msgAnnotationsMatcher.withEntry(AmqpMessageSupport.JMS_MSG_TYPE, equalTo(AmqpMessageSupport.JMS_STREAM_MESSAGE));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setMessageContentMatcher(new EncodedAmqpSequenceMatcher(list));

        testPeer.expectTransfer(messageMatcher);
        testPeer.expectClose();

        producer.send(streamMessage);

        try {
            streamMessage.writeString(myString);
            fail("Message should not be writable after a send.");
        } catch (MessageNotWriteableException mnwe) {}

        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 15
Source File: MessageCreator.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private static Message createMessage(final MessageDescription messageDescription,
                                     final Session session)
        throws Exception
{
    Message message;
    try
    {
        switch (messageDescription.getMessageType())
        {
            case MESSAGE:
                message = session.createTextMessage();
                break;
            case BYTES_MESSAGE:
                message = session.createBytesMessage();
                ((BytesMessage) message).writeBytes(((byte[]) messageDescription.getContent()));
                break;
            case MAP_MESSAGE:
                message = session.createMapMessage();
                for (Map.Entry<String, Object> entry : ((Map<String, Object>) messageDescription.getContent()).entrySet())
                {
                    ((MapMessage) message).setObject(entry.getKey(), entry.getValue());
                }
                break;
            case OBJECT_MESSAGE:
                message = session.createObjectMessage((Serializable) messageDescription.getContent());
                break;
            case STREAM_MESSAGE:
                message = session.createStreamMessage();
                for (Object item : (Collection<?>) messageDescription.getContent())
                {
                    ((StreamMessage) message).writeObject(item);
                }
                break;
            case TEXT_MESSAGE:
                message = session.createTextMessage(messageDescription.getContent().toString());
                break;
            default:
                throw new RuntimeException(String.format("unexpected message type '%s'",
                                                         messageDescription.getMessageType()));
        }
    }
    catch (ClassCastException e)
    {
        throw new RuntimeException(String.format("Could not create message of type '%s' with this body: %s",
                                                 messageDescription.getMessageType(),
                                                 messageDescription.getContent().toString()), e);
    }
    return message;
}
 
Example 16
Source File: JMSTestUtil.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * @param testcase
 * @param session
 * @param rtd
 * @return
 * @throws JMSException
 */
public static Message buildJMSMessageFromTestCase(TestCaseType testcase, Session session,
                                                  Destination rtd) throws JMSException {
    MessagePropertiesType messageProperties = testcase.getRequestMessage();
    Message jmsMessage = null;
    String messageType = messageProperties.getMessageType();
    if ("text".equals(messageType)) {
        jmsMessage = session.createTextMessage();
        ((TextMessage)jmsMessage).setText("test");
    } else if ("byte".equals(messageType)) {
        jmsMessage = session.createBytesMessage();
    } else if ("stream".equals(messageType)) {
        jmsMessage = session.createStreamMessage();
        ((StreamMessage)jmsMessage).writeString("test");
    } else {
        jmsMessage = session.createBytesMessage();
    }

    jmsMessage.setJMSReplyTo(rtd);

    if (messageProperties.isSetDeliveryMode()) {
        jmsMessage.setJMSDeliveryMode(messageProperties.getDeliveryMode());
    }
    if (messageProperties.isSetExpiration()) {
        jmsMessage.setJMSExpiration(messageProperties.getExpiration());
    }
    if (messageProperties.isSetPriority()) {
        jmsMessage.setJMSPriority(messageProperties.getPriority());
    }
    if (messageProperties.isSetExpiration()) {
        jmsMessage.setJMSPriority(messageProperties.getExpiration());
    }
    if (messageProperties.isSetCorrelationID()) {
        jmsMessage.setJMSCorrelationID(messageProperties.getCorrelationID());
    }

    if (messageProperties.isSetTargetService()
        && !"".equals(messageProperties.getTargetService().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.TARGETSERVICE_FIELD, messageProperties
            .getTargetService().trim());
    }

    if (messageProperties.isSetBindingVersion()
        && !"".equals(messageProperties.getBindingVersion().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.BINDINGVERSION_FIELD, messageProperties
                                     .getBindingVersion().trim());
    }

    if (messageProperties.isSetContentType()
        && !"".equals(messageProperties.getContentType().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.CONTENTTYPE_FIELD, messageProperties
            .getContentType().trim());
    }

    if (messageProperties.isSetSoapAction()
        && !"".equals(messageProperties.getSoapAction().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.SOAPACTION_FIELD, messageProperties
            .getSoapAction().trim());
    }

    if (messageProperties.isSetRequestURI()
        && !"".equals(messageProperties.getRequestURI().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.REQUESTURI_FIELD, messageProperties
            .getRequestURI().trim());
    }
    return jmsMessage;
}
 
Example 17
Source File: PutJMS.java    From nifi with Apache License 2.0 4 votes vote down vote up
private Message createMessage(final Session jmsSession, final ProcessContext context, final byte[] messageContent,
        final FlowFile flowFile, final Destination replyToQueue, final Integer priority) throws JMSException {
    final Message message;

    switch (context.getProperty(MESSAGE_TYPE).getValue()) {
        case MSG_TYPE_EMPTY: {
            message = jmsSession.createTextMessage("");
            break;
        }
        case MSG_TYPE_STREAM: {
            final StreamMessage streamMessage = jmsSession.createStreamMessage();
            streamMessage.writeBytes(messageContent);
            message = streamMessage;
            break;
        }
        case MSG_TYPE_TEXT: {
            message = jmsSession.createTextMessage(new String(messageContent, UTF8));
            break;
        }
        case MSG_TYPE_MAP: {
            message = jmsSession.createMapMessage();
            break;
        }
        case MSG_TYPE_BYTE:
        default: {
            final BytesMessage bytesMessage = jmsSession.createBytesMessage();
            bytesMessage.writeBytes(messageContent);
            message = bytesMessage;
        }
    }

    message.setJMSTimestamp(System.currentTimeMillis());

    if (replyToQueue != null) {
        message.setJMSReplyTo(replyToQueue);
    }

    if (priority != null) {
        message.setJMSPriority(priority);
    }

    if (context.getProperty(ATTRIBUTES_TO_JMS_PROPS).asBoolean()) {
        copyAttributesToJmsProps(flowFile, message);
    }

    return message;
}