Java Code Examples for javax.jms.BytesMessage#writeByte()
The following examples show how to use
javax.jms.BytesMessage#writeByte() .
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: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void bytesMessage() throws Exception { context = cf.createContext(); try { JMSProducer producer = context.createProducer(); BytesMessage bMsg = context.createBytesMessage(); bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest"); bMsg.writeByte((byte) 1); bMsg.writeInt(22); CountDownLatch latch = new CountDownLatch(1); SimpleCompletionListener listener = new SimpleCompletionListener(latch); producer.setAsync(listener); producer.send(queue1, bMsg); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertEquals(listener.message.readByte(), (byte) 1); assertEquals(listener.message.readInt(), 22); } finally { context.close(); } }
Example 2
Source File: BytesMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void prepareMessage(final Message m) throws JMSException { super.prepareMessage(m); BytesMessage bm = (BytesMessage) m; bm.writeBoolean(true); bm.writeByte((byte) 3); bm.writeBytes(new byte[]{(byte) 4, (byte) 5, (byte) 6}); bm.writeChar((char) 7); bm.writeDouble(8.0); bm.writeFloat(9.0f); bm.writeInt(10); bm.writeLong(11L); bm.writeShort((short) 12); bm.writeUTF("this is an UTF String"); bm.reset(); }
Example 3
Source File: MessageHeaderTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testCopyOnForeignBytesMessage() throws JMSException { ClientMessage clientMessage = new ClientMessageImpl(ActiveMQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 4, 1000); ClientSession session = new FakeSession(clientMessage); BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage(); for (int i = 0; i < 20; i++) { foreignBytesMessage.writeByte((byte) i); } ActiveMQBytesMessage copy = new ActiveMQBytesMessage(foreignBytesMessage, session); foreignBytesMessage.reset(); copy.reset(); MessageHeaderTestBase.ensureEquivalent(foreignBytesMessage, copy); }
Example 4
Source File: JmsContextTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testReceiveBytes() throws Exception { JMSProducer producer = context.createProducer(); JMSConsumer consumer = context.createConsumer(queue1); BytesMessage bytesSend = context.createBytesMessage(); bytesSend.writeByte((byte) 1); bytesSend.writeLong(2L); producer.send(queue1, bytesSend); BytesMessage msgReceived = (BytesMessage) consumer.receiveNoWait(); byte[] bytesArray = msgReceived.getBody(byte[].class); assertEquals((byte) 1, msgReceived.readByte()); assertEquals(2L, msgReceived.readLong()); DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytesArray)); assertEquals((byte) 1, dataInputStream.readByte()); assertEquals(2L, dataInputStream.readLong()); }
Example 5
Source File: BodyIsAssignableFromTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * @param type * @throws JMSException */ private Object createBodySendAndReceive(JmsMessageType type) throws JMSException { Object res = null; Message msg = null; switch (type) { case BYTE: BytesMessage mByte = queueProducerSession.createBytesMessage(); final int size = 20; byte[] resByte = new byte[size]; for (int i = 0; i < size; i++) { resByte[i] = (byte) i; mByte.writeByte((byte) i); } msg = mByte; res = resByte; break; case TEXT: res = "JMS2"; msg = queueProducerSession.createTextMessage("JMS2"); break; case STREAM: msg = queueProducerSession.createStreamMessage(); break; case OBJECT: res = new Double(37.6); msg = queueProducerSession.createObjectMessage(new Double(37.6)); break; case MAP: MapMessage msg1 = queueProducerSession.createMapMessage(); msg1.setInt("int", 13); msg1.setLong("long", 37L); msg1.setString("string", "crocodile"); msg = msg1; Map<String, Object> map = new HashMap<>(); map.put("int", Integer.valueOf(13)); map.put("long", Long.valueOf(37L)); map.put("string", "crocodile"); res = map; break; default: Assert.fail("no default..."); } Assert.assertNotNull(msg); msg.setStringProperty("type", type.toString()); queueProducer.send(msg); return res; }