Search in sources :

Example 76 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class GeneralInteropTest method testMutipleReceivingFromCore.

@Test
public void testMutipleReceivingFromCore() throws Exception {
    final String text = "HelloWorld";
    final int num = 100;
    // text messages
    sendMultipleTextMessagesUsingCoreJms(queueName, text, 100);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    for (int i = 0; i < num; i++) {
        TextMessage textMessage = (TextMessage) consumer.receive(5000);
        assertEquals(text + i, textMessage.getText());
        assertEquals(destination, textMessage.getJMSDestination());
    }
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 77 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class GeneralInteropTest method sendMultipleTextMessagesUsingOpenWire.

private void sendMultipleTextMessagesUsingOpenWire(String text, int num) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    for (int i = 0; i < num; i++) {
        TextMessage textMessage = session.createTextMessage(text + i);
        producer.send(textMessage);
    }
}
Also used : ActiveMQMessageProducer(org.apache.activemq.ActiveMQMessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 78 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class GeneralInteropTest method testReceivingFromCore.

@Test
public void testReceivingFromCore() throws Exception {
    final String text = "HelloWorld";
    // text messages
    sendTextMessageUsingCoreJms(queueName, text);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageConsumer consumer = (ActiveMQMessageConsumer) session.createConsumer(destination);
    TextMessage textMessage = (TextMessage) consumer.receive(5000);
    assertEquals(text, textMessage.getText());
    assertEquals(destination, textMessage.getJMSDestination());
    // map messages
    sendMapMessageUsingCoreJms(queueName);
    MapMessage mapMessage = (MapMessage) consumer.receive(5000);
    assertEquals(destination, mapMessage.getJMSDestination());
    assertTrue(mapMessage.getBoolean("aboolean"));
    assertEquals((byte) 4, mapMessage.getByte("abyte"));
    byte[] bytes = mapMessage.getBytes("abytes");
    assertEquals(2, bytes.length);
    assertEquals((byte) 4, bytes[0]);
    assertEquals((byte) 5, bytes[1]);
    assertEquals('a', mapMessage.getChar("achar"));
    Double doubleVal = mapMessage.getDouble("adouble");
    assertTrue(doubleVal.equals(Double.valueOf(4.4)));
    Float floatVal = mapMessage.getFloat("afloat");
    assertTrue(floatVal.equals(Float.valueOf(4.5F)));
    assertEquals(40, mapMessage.getInt("aint"));
    assertEquals(80L, mapMessage.getLong("along"));
    assertEquals(65, mapMessage.getShort("ashort"));
    assertEquals("hello", mapMessage.getString("astring"));
    // object message
    SimpleSerializable obj = new SimpleSerializable();
    sendObjectMessageUsingCoreJms(queueName, obj);
    ObjectMessage objectMessage = (ObjectMessage) consumer.receive(5000);
    SimpleSerializable data = (SimpleSerializable) objectMessage.getObject();
    assertEquals(obj.objName, data.objName);
    assertEquals(obj.intVal, data.intVal);
    assertEquals(obj.longVal, data.longVal);
    // stream messages
    sendStreamMessageUsingCoreJms(queueName);
    StreamMessage streamMessage = (StreamMessage) consumer.receive(5000);
    assertEquals(destination, streamMessage.getJMSDestination());
    assertTrue(streamMessage.readBoolean());
    assertEquals((byte) 2, streamMessage.readByte());
    byte[] streamBytes = new byte[2];
    streamMessage.readBytes(streamBytes);
    assertEquals(6, streamBytes[0]);
    assertEquals(7, streamBytes[1]);
    assertEquals('b', streamMessage.readChar());
    Double streamDouble = streamMessage.readDouble();
    assertTrue(streamDouble.equals(Double.valueOf(6.5)));
    Float streamFloat = streamMessage.readFloat();
    assertTrue(streamFloat.equals(Float.valueOf(93.9F)));
    assertEquals(7657, streamMessage.readInt());
    assertEquals(239999L, streamMessage.readLong());
    assertEquals((short) 34222, streamMessage.readShort());
    assertEquals("hello streammessage", streamMessage.readString());
    // bytes messages
    final byte[] bytesData = text.getBytes(StandardCharsets.UTF_8);
    sendBytesMessageUsingCoreJms(queueName, bytesData);
    BytesMessage bytesMessage = (BytesMessage) consumer.receive(5000);
    byte[] rawBytes = new byte[bytesData.length];
    bytesMessage.readBytes(rawBytes);
    for (int i = 0; i < bytesData.length; i++) {
        assertEquals("failed at " + i, bytesData[i], rawBytes[i]);
    }
    assertTrue(bytesMessage.readBoolean());
    assertEquals(99999L, bytesMessage.readLong());
    assertEquals('h', bytesMessage.readChar());
    assertEquals(987, bytesMessage.readInt());
    assertEquals((short) 1099, bytesMessage.readShort());
    assertEquals("hellobytes", bytesMessage.readUTF());
    // generic message
    sendMessageUsingCoreJms(queueName);
    javax.jms.Message genericMessage = consumer.receive(5000);
    assertEquals(destination, genericMessage.getJMSDestination());
    String value = genericMessage.getStringProperty("stringProperty");
    assertEquals("HelloMessage", value);
    assertFalse(genericMessage.getBooleanProperty("booleanProperty"));
    assertEquals(99999L, genericMessage.getLongProperty("longProperty"));
    assertEquals(979, genericMessage.getIntProperty("intProperty"));
    assertEquals((short) 1099, genericMessage.getShortProperty("shortProperty"));
    assertEquals("HelloMessage", genericMessage.getStringProperty("stringProperty"));
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MapMessage(javax.jms.MapMessage) BytesMessage(javax.jms.BytesMessage) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ObjectMessage(javax.jms.ObjectMessage) StreamMessage(javax.jms.StreamMessage) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) BasicOpenWireTest(org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest) Test(org.junit.Test)

Example 79 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class GeneralInteropTest method sendMapMessageUsingOpenWire.

private void sendMapMessageUsingOpenWire() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    MapMessage mapMessage = session.createMapMessage();
    mapMessage.setBoolean("aboolean", true);
    mapMessage.setByte("abyte", (byte) 4);
    mapMessage.setBytes("abytes", new byte[] { 4, 5 });
    mapMessage.setChar("achar", 'a');
    mapMessage.setDouble("adouble", 4.4);
    mapMessage.setFloat("afloat", 4.5f);
    mapMessage.setInt("aint", 40);
    mapMessage.setLong("along", 80L);
    mapMessage.setShort("ashort", (short) 65);
    mapMessage.setString("astring", "hello");
    producer.send(mapMessage);
}
Also used : ActiveMQMessageProducer(org.apache.activemq.ActiveMQMessageProducer) MapMessage(javax.jms.MapMessage) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 80 with ActiveMQDestination

use of org.apache.activemq.command.ActiveMQDestination in project activemq-artemis by apache.

the class GeneralInteropTest method sendMessageUsingOpenWire.

private void sendMessageUsingOpenWire(String queueName) throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    System.out.println("destination: " + destination);
    final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);
    javax.jms.Message message = session.createMessage();
    message.setBooleanProperty("booleanProperty", false);
    message.setLongProperty("longProperty", 99999L);
    message.setByteProperty("byteProperty", (byte) 5);
    message.setIntProperty("intProperty", 979);
    message.setShortProperty("shortProperty", (short) 1099);
    message.setStringProperty("stringProperty", "HelloMessage");
    producer.send(message);
}
Also used : ActiveMQMessageProducer(org.apache.activemq.ActiveMQMessageProducer) Session(javax.jms.Session) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)165 Session (javax.jms.Session)62 MessageConsumer (javax.jms.MessageConsumer)49 Message (org.apache.activemq.command.Message)46 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)45 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)44 SessionInfo (org.apache.activemq.command.SessionInfo)44 ProducerInfo (org.apache.activemq.command.ProducerInfo)42 Test (org.junit.Test)41 Message (javax.jms.Message)40 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)40 TextMessage (javax.jms.TextMessage)31 BasicOpenWireTest (org.apache.activemq.artemis.tests.integration.openwire.BasicOpenWireTest)24 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)22 MessageProducer (javax.jms.MessageProducer)18 XATransactionId (org.apache.activemq.command.XATransactionId)15 CountDownLatch (java.util.concurrent.CountDownLatch)14 ActiveMQMessageProducer (org.apache.activemq.ActiveMQMessageProducer)12 MessageAck (org.apache.activemq.command.MessageAck)12 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)11