Java Code Examples for javax.jms.StreamMessage#writeBytes()
The following examples show how to use
javax.jms.StreamMessage#writeBytes() .
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: CompressedInteropTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 2
Source File: GeneralInteropTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 3
Source File: MessageCompressionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 4
Source File: StreamMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void prepareMessage(final Message m) throws JMSException { super.prepareMessage(m); StreamMessage sm = (StreamMessage) m; sm.writeBoolean(true); sm.writeByte((byte) 3); sm.writeBytes(new byte[]{(byte) 4, (byte) 5, (byte) 6}); sm.writeChar((char) 7); sm.writeDouble(8.0); sm.writeFloat(9.0f); sm.writeInt(10); sm.writeLong(11L); sm.writeObject("this is an object"); sm.writeShort((short) 12); sm.writeString("this is a String"); }
Example 5
Source File: ConsumeJMSManualTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testStreamMessage() throws Exception { MessageCreator messageCreator = session -> { StreamMessage message = session.createStreamMessage(); message.writeBoolean(true); message.writeByte(Integer.valueOf(1).byteValue()); message.writeBytes(new byte[] {2, 3, 4}); message.writeShort((short)32); message.writeInt(64); message.writeLong(128L); message.writeFloat(1.25F); message.writeDouble(100.867); message.writeChar('c'); message.writeString("someString"); message.writeObject("stringAsObject"); return message; }; send(messageCreator); }
Example 6
Source File: MessageSender.java From fixflow with Apache License 2.0 | 6 votes |
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 7
Source File: JMSQueueMessageProducer.java From micro-integrator with Apache License 2.0 | 5 votes |
/** * Method to send a StreamMessage. * * @param payload content of the StreamMessage to be sent * @throws JMSException if an error occurs sending the BytesMessage */ public void sendStreamMessage(byte[] payload) throws JMSException { checkIfConnected(); StreamMessage streamMessage = session.createStreamMessage(); streamMessage.writeBytes(payload); producer.send(streamMessage); }
Example 8
Source File: TestGetJMSQueue.java From localization_nifi with Apache License 2.0 | 5 votes |
@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 9
Source File: JMSQueueMessageProducer.java From product-ei with Apache License 2.0 | 5 votes |
/** * Method to send a StreamMessage. * * @param payload content of the StreamMessage to be sent * @throws JMSException if an error occurs sending the BytesMessage */ public void sendStreamMessage(byte[] payload) throws JMSException { checkIfConnected(); StreamMessage streamMessage = session.createStreamMessage(); streamMessage.writeBytes(payload); producer.send(streamMessage); }
Example 10
Source File: GeneralInteropTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
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 11
Source File: TestGetJMSQueue.java From nifi with Apache License 2.0 | 5 votes |
@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 12
Source File: PutJMS.java From localization_nifi with Apache License 2.0 | 4 votes |
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: PutJMS.java From nifi with Apache License 2.0 | 4 votes |
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 14
Source File: JMSPublisherConsumerIT.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testStreamMessage() throws Exception { final String destinationName = "testStreamMessage"; MessageCreator messageCreator = session -> { StreamMessage message = session.createStreamMessage(); message.writeBoolean(true); message.writeByte(Integer.valueOf(1).byteValue()); message.writeBytes(new byte[] {2, 3, 4}); message.writeShort((short)32); message.writeInt(64); message.writeLong(128L); message.writeFloat(1.25F); message.writeDouble(100.867); message.writeChar('c'); message.writeString("someString"); message.writeObject("stringAsObject"); return message; }; byte[] expected; try ( ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); ) { dataOutputStream.writeBoolean(true); dataOutputStream.writeByte(1); dataOutputStream.write(new byte[] {2, 3, 4}); dataOutputStream.writeShort((short)32); dataOutputStream.writeInt(64); dataOutputStream.writeLong(128L); dataOutputStream.writeFloat(1.25F); dataOutputStream.writeDouble(100.867); dataOutputStream.writeChar('c'); dataOutputStream.writeUTF("someString"); dataOutputStream.writeUTF("stringAsObject"); dataOutputStream.flush(); expected = byteArrayOutputStream.toByteArray(); } ConsumerCallback responseChecker = response -> { byte[] actual = response.getMessageBody(); assertArrayEquals( expected, actual ); }; testMessage(destinationName, messageCreator, responseChecker); }