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());
}
}
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);
}
}
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"));
}
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);
}
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);
}
Aggregations