Ejemplo n.º 1
0
 @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((int) 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(), (int) 22);
   } finally {
     context.close();
   }
 }
Ejemplo n.º 2
0
  @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());
  }