Java Code Examples for javax.jms.StreamMessage#writeString()
The following examples show how to use
javax.jms.StreamMessage#writeString() .
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: JMSMessageTypesTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 4
Source File: CompressionOverNetworkTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testStreamMessageCompression() throws Exception { MessageConsumer consumer1 = remoteSession.createConsumer(included); MessageProducer producer = localSession.createProducer(included); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); waitForConsumerRegistration(localBroker, 1, included); StreamMessage test = localSession.createStreamMessage(); for (int i = 0; i < 100; ++i) { test.writeString("test string: " + i); } producer.send(test); Message msg = consumer1.receive(RECEIVE_TIMEOUT_MILLS); assertNotNull(msg); ActiveMQStreamMessage message = (ActiveMQStreamMessage) msg; assertTrue(message.isCompressed()); for (int i = 0; i < 100; ++i) { assertEquals("test string: " + i, message.readString()); } }
Example 5
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 6
Source File: MessageTypeTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Send a <code>StreamMessage</code> with 2 Java primitives in its body (a <code> * String</code> and a <code>double</code>). * <br /> * Receive it and test that the values of the primitives of the body are correct */ @Test public void testStreamMessage_2() { try { StreamMessage message = senderSession.createStreamMessage(); message.writeString("pi"); message.writeDouble(3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); Assert.assertTrue("The message should be an instance of StreamMessage.\n", m instanceof StreamMessage); StreamMessage msg = (StreamMessage) m; Assert.assertEquals("pi", msg.readString()); Assert.assertEquals(3.14159, msg.readDouble(), 0); } catch (JMSException e) { fail(e); } }
Example 7
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 8
Source File: JmsProduceMessageTypesTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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 9
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 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: SimpleOpenWireTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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: MessageConsumerTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@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 13
Source File: StreamMessageIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@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 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); }
Example 15
Source File: StreamMessageTest.java From activemq-artemis with Apache License 2.0 | 3 votes |
@Test public void testNullValue() throws Exception { StreamMessage m = session.createStreamMessage(); m.writeString(null); queueProd.send(m); conn.start(); StreamMessage rm = (StreamMessage) queueCons.receive(); ProxyAssertSupport.assertNull(rm.readString()); }