Java Code Examples for javax.jms.Session#createMapMessage()

The following examples show how to use javax.jms.Session#createMapMessage() . 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: MessageCompressionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendTestMapMessage(ActiveMQConnectionFactory factory, String message) throws JMSException {
   ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageProducer producer = session.createProducer(queue);
   MapMessage mapMessage = session.createMapMessage();

   mapMessage.setBoolean("boolean-type", true);
   mapMessage.setByte("byte-type", (byte) 10);
   mapMessage.setBytes("bytes-type", TEXT.getBytes());
   mapMessage.setChar("char-type", 'A');
   mapMessage.setDouble("double-type", 55.3D);
   mapMessage.setFloat("float-type", 79.1F);
   mapMessage.setInt("int-type", 37);
   mapMessage.setLong("long-type", 56652L);
   mapMessage.setObject("object-type", new String("VVVV"));
   mapMessage.setShort("short-type", (short) 333);
   mapMessage.setString("string-type", TEXT);

   producer.send(mapMessage);
   connection.close();
}
 
Example 2
Source File: CompressedInteropTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void sendCompressedMapMessageUsingOpenWire() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   ActiveMQDestination destination = createDestination(session, ActiveMQDestination.QUEUE_TYPE);

   final ActiveMQMessageProducer producer = (ActiveMQMessageProducer) session.createProducer(destination);

   MapMessage mapMessage = session.createMapMessage();

   mapMessage.setBoolean("boolean-type", true);
   mapMessage.setByte("byte-type", (byte) 10);
   mapMessage.setBytes("bytes-type", TEXT.getBytes());
   mapMessage.setChar("char-type", 'A');
   mapMessage.setDouble("double-type", 55.3D);
   mapMessage.setFloat("float-type", 79.1F);
   mapMessage.setInt("int-type", 37);
   mapMessage.setLong("long-type", 56652L);
   mapMessage.setObject("object-type", new String("VVVV"));
   mapMessage.setShort("short-type", (short) 333);
   mapMessage.setString("string-type", TEXT);

   producer.send(mapMessage);
}
 
Example 3
Source File: MessageOrderingTest.java    From olat with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("tcp://localhost:61616");

    Connection connection = connectionFactory.createQueueConnection();
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Destination destination = new ActiveMQQueue("/atestqueue");

    MessageProducer producer = session1.createProducer(destination);

    MessageConsumer consumer = session2.createConsumer(destination);

    consumer.setMessageListener(new MessageOrderingTest());
    connection.start();

    for (int i = 0; i < 10000; i++) {
        MapMessage message = session1.createMapMessage();
        message.setInt("Counter", i);
        producer.send(message);
        System.out.println("Sent counter=" + i);
    }
}
 
Example 4
Source File: CompressedMessageContentTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private Map<String, Object> sendCompressibleMapMessage() throws Exception
{
    final Map<String, Object> mapToSend = createCompressibleMapMessage();

    Connection senderConnection = getConnection(true);
    try
    {
        Session session = senderConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        MessageProducer producer = session.createProducer(session.createQueue(TEST_QUEUE));
        MapMessage sentMessage = session.createMapMessage();
        for(Map.Entry<String,Object> entry: mapToSend.entrySet())
        {
            String key =  entry.getKey();
            Object value =  entry.getValue();
            sentMessage.setObject(key, value);
        }

        producer.send(sentMessage);
    }
    finally
    {
        senderConnection.close();
    }
    return mapToSend;
}
 
Example 5
Source File: AmqpManagementFacade.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
public void deleteEntityUsingAmqpManagement(final String name, final Session session, final String type)
        throws JMSException
{
    MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));

    MapMessage createMessage = session.createMapMessage();
    createMessage.setStringProperty("type", type);
    createMessage.setStringProperty("operation", "DELETE");
    createMessage.setStringProperty("index", "object-path");

    createMessage.setStringProperty("key", name);
    producer.send(createMessage);
    if (session.getTransacted())
    {
        session.commit();
    }
}
 
Example 6
Source File: AmqpManagementFacade.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void updateEntityUsingAmqpManagement(final String name,
                                             final String type,
                                             Map<String, Object> attributes,
                                             Destination replyToDestination,
                                             final Session session)
        throws JMSException
{
    MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));

    MapMessage createMessage = session.createMapMessage();
    createMessage.setStringProperty("type", type);
    createMessage.setStringProperty("operation", "UPDATE");
    createMessage.setStringProperty("index", "object-path");
    createMessage.setStringProperty("key", name);
    createMessage.setJMSReplyTo(replyToDestination);
    for (Map.Entry<String, Object> entry : attributes.entrySet())
    {
        createMessage.setObject(entry.getKey(), entry.getValue());
    }
    producer.send(createMessage);
    if (session.getTransacted())
    {
        session.commit();
    }
    producer.close();
}
 
Example 7
Source File: MessageOrderingTest.java    From olat with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
    connectionFactory.setBrokerURL("tcp://localhost:61616");

    Connection connection = connectionFactory.createQueueConnection();
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Destination destination = new ActiveMQQueue("/atestqueue");

    MessageProducer producer = session1.createProducer(destination);

    MessageConsumer consumer = session2.createConsumer(destination);

    consumer.setMessageListener(new MessageOrderingTest());
    connection.start();

    for (int i = 0; i < 10000; i++) {
        MapMessage message = session1.createMapMessage();
        message.setInt("Counter", i);
        producer.send(message);
        System.out.println("Sent counter=" + i);
    }
}
 
Example 8
Source File: ReSendMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testResendWithLargeMessage() throws Exception {
   conn = cf.createConnection();
   conn.start();

   Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
   ArrayList<Message> msgs = new ArrayList<>();

   for (int i = 0; i < 10; i++) {
      BytesMessage bm = sess.createBytesMessage();
      bm.setObjectProperty(ActiveMQJMSConstants.JMS_ACTIVEMQ_INPUT_STREAM, ActiveMQTestBase.createFakeLargeStream(2 * ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE));
      msgs.add(bm);

      MapMessage mm = sess.createMapMessage();
      mm.setBoolean("boolean", true);
      mm.setByte("byte", (byte) 3);
      mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5});
      mm.setChar("char", (char) 6);
      mm.setDouble("double", 7.0);
      mm.setFloat("float", 8.0f);
      mm.setInt("int", 9);
      mm.setLong("long", 10L);
      mm.setObject("object", new String("this is an object"));
      mm.setShort("short", (short) 11);
      mm.setString("string", "this is a string");

      msgs.add(mm);
      msgs.add(sess.createTextMessage("hello" + i));
      msgs.add(sess.createObjectMessage(new SomeSerializable("hello" + i)));
   }

   internalTestResend(msgs, sess);
}
 
Example 9
Source File: TransactionTimeoutTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private void enableTransactionTimeout(final Map<String, Object> attrs) throws Exception
{
    Connection connection = getConnection();
    try
    {
        final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

        final Queue queue;
        if(getProtocol() == Protocol.AMQP_1_0)
        {
            queue = session.createQueue("$management");
        }
        else
        {
            queue = session.createQueue("ADDR:$management");
        }

        final MessageProducer _producer = session.createProducer(queue);
        MapMessage message = session.createMapMessage();

        message.setStringProperty("type", "org.apache.qpid.VirtualHost");
        message.setStringProperty("operation", "UPDATE");
        message.setStringProperty("index", "object-path");
        message.setStringProperty("key", "");

        for (final Map.Entry<String, Object> entry : attrs.entrySet())
        {
            message.setObject(entry.getKey(), entry.getValue());
        }

        _producer.send(message);
        session.commit();
    }
    finally
    {
        connection.close();
    }
}
 
Example 10
Source File: SimpleMessageConverter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create a JMS MapMessage for the given Map.
 * @param map the Map to convert
 * @param session current JMS session
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @see javax.jms.Session#createMapMessage
 */
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
	MapMessage message = session.createMapMessage();
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		Object key = entry.getKey();
		if (!(key instanceof String)) {
			throw new MessageConversionException("Cannot convert non-String key of type [" +
					ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
		}
		message.setObject((String) key, entry.getValue());
	}
	return message;
}
 
Example 11
Source File: ReSendMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testResendWithMapMessagesOnly() throws Exception {
   conn = cf.createConnection();
   conn.start();

   Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
   ArrayList<Message> msgs = new ArrayList<>();

   for (int i = 0; i < 1; i++) {
      MapMessage mm = sess.createMapMessage();
      mm.setBoolean("boolean", true);
      mm.setByte("byte", (byte) 3);
      mm.setBytes("bytes", new byte[]{(byte) 3, (byte) 4, (byte) 5});
      mm.setChar("char", (char) 6);
      mm.setDouble("double", 7.0);
      mm.setFloat("float", 8.0f);
      mm.setInt("int", 9);
      mm.setLong("long", 10L);
      mm.setObject("object", new String("this is an object"));
      mm.setShort("short", (short) 11);
      mm.setString("string", "this is a string");

      msgs.add(mm);

      MapMessage emptyMap = sess.createMapMessage();
      msgs.add(emptyMap);
   }

   internalTestResend(msgs, sess);
}
 
Example 12
Source File: GeneralInteropTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void sendMapMessageUsingCoreJms(String queueName) throws Exception {
   Connection jmsConn = null;
   try {
      jmsConn = coreCf.createConnection();
      Session session = jmsConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      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");

      Queue queue = session.createQueue(queueName);
      MessageProducer producer = session.createProducer(queue);

      producer.send(mapMessage);
   } finally {
      if (jmsConn != null) {
         jmsConn.close();
      }
   }

}
 
Example 13
Source File: JMSMessageTypesTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void testMapMessageSendReceive(Connection producerConnection, Connection consumerConnection) throws Throwable {
   long time = System.currentTimeMillis();

   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++) {
      instanceLog.debug("Sending " + i);
      MapMessage message = session.createMapMessage();

      message.setInt("i", i);
      message.setIntProperty("count", i);
      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++) {
      MapMessage m = (MapMessage) consumer.receive(5000);
      Assert.assertNotNull("Could not receive message count=" + i + " on consumer", m);

      Assert.assertEquals(i, m.getInt("i"));
      Assert.assertEquals(i, m.getIntProperty("count"));
   }

   long taken = (System.currentTimeMillis() - time) / 1000;
   instanceLog.debug("taken = " + taken);
}
 
Example 14
Source File: SampleMessageConverter.java    From tutorials with MIT License 5 votes vote down vote up
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
    Employee employee = (Employee) object;
    MapMessage message = session.createMapMessage();
    message.setString("name", employee.getName());
    message.setInt("age", employee.getAge());
    return message;
}
 
Example 15
Source File: SimpleMessageConverter.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create a JMS MapMessage for the given Map.
 * @param map the Map to convert
 * @param session current JMS session
 * @return the resulting message
 * @throws JMSException if thrown by JMS methods
 * @see javax.jms.Session#createMapMessage
 */
protected MapMessage createMessageForMap(Map<?, ?> map, Session session) throws JMSException {
	MapMessage message = session.createMapMessage();
	for (Map.Entry<?, ?> entry : map.entrySet()) {
		Object key = entry.getKey();
		if (!(key instanceof String)) {
			throw new MessageConversionException("Cannot convert non-String key of type [" +
					ObjectUtils.nullSafeClassName(key) + "] to JMS MapMessage entry");
		}
		message.setObject((String) key, entry.getValue());
	}
	return message;
}
 
Example 16
Source File: MessageCreator.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private static Message createMessage(final MessageDescription messageDescription,
                                     final Session session)
        throws Exception
{
    Message message;
    try
    {
        switch (messageDescription.getMessageType())
        {
            case MESSAGE:
                message = session.createTextMessage();
                break;
            case BYTES_MESSAGE:
                message = session.createBytesMessage();
                ((BytesMessage) message).writeBytes(((byte[]) messageDescription.getContent()));
                break;
            case MAP_MESSAGE:
                message = session.createMapMessage();
                for (Map.Entry<String, Object> entry : ((Map<String, Object>) messageDescription.getContent()).entrySet())
                {
                    ((MapMessage) message).setObject(entry.getKey(), entry.getValue());
                }
                break;
            case OBJECT_MESSAGE:
                message = session.createObjectMessage((Serializable) messageDescription.getContent());
                break;
            case STREAM_MESSAGE:
                message = session.createStreamMessage();
                for (Object item : (Collection<?>) messageDescription.getContent())
                {
                    ((StreamMessage) message).writeObject(item);
                }
                break;
            case TEXT_MESSAGE:
                message = session.createTextMessage(messageDescription.getContent().toString());
                break;
            default:
                throw new RuntimeException(String.format("unexpected message type '%s'",
                                                         messageDescription.getMessageType()));
        }
    }
    catch (ClassCastException e)
    {
        throw new RuntimeException(String.format("Could not create message of type '%s' with this body: %s",
                                                 messageDescription.getMessageType(),
                                                 messageDescription.getContent().toString()), e);
    }
    return message;
}
 
Example 17
Source File: MapMessageIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testSendBasicMapMessage() 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 myBoolKey = "myBool";
        boolean myBool = true;
        String myByteKey = "myByte";
        byte myByte = 4;
        String myBytesKey = "myBytes";
        byte[] myBytes = myBytesKey.getBytes();
        String myCharKey = "myChar";
        char myChar = 'd';
        String myDoubleKey = "myDouble";
        double myDouble = 1234567890123456789.1234;
        String myFloatKey = "myFloat";
        float myFloat = 1.1F;
        String myIntKey = "myInt";
        int myInt = Integer.MAX_VALUE;
        String myLongKey = "myLong";
        long myLong = Long.MAX_VALUE;
        String myShortKey = "myShort";
        short myShort = 25;
        String myStringKey = "myString";
        String myString = myStringKey;

        // Prepare a MapMessage to send to the test peer to send
        MapMessage mapMessage = session.createMapMessage();

        mapMessage.setBoolean(myBoolKey, myBool);
        mapMessage.setByte(myByteKey, myByte);
        mapMessage.setBytes(myBytesKey, myBytes);
        mapMessage.setChar(myCharKey, myChar);
        mapMessage.setDouble(myDoubleKey, myDouble);
        mapMessage.setFloat(myFloatKey, myFloat);
        mapMessage.setInt(myIntKey, myInt);
        mapMessage.setLong(myLongKey, myLong);
        mapMessage.setShort(myShortKey, myShort);
        mapMessage.setString(myStringKey, myString);

        // prepare a matcher for the test peer to use to receive and verify the message
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put(myBoolKey, myBool);
        map.put(myByteKey, myByte);
        map.put(myBytesKey, new Binary(myBytes));// the underlying AMQP message uses Binary rather than byte[] directly.
        // TODO: see note above to explain the ugly cast
        map.put(myCharKey, (int) myChar);
        map.put(myDoubleKey, myDouble);
        map.put(myFloatKey, myFloat);
        map.put(myIntKey, myInt);
        map.put(myLongKey, myLong);
        map.put(myShortKey, myShort);
        map.put(myStringKey, myString);

        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        msgAnnotationsMatcher.withEntry(AmqpMessageSupport.JMS_MSG_TYPE, equalTo(AmqpMessageSupport.JMS_MAP_MESSAGE));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(map));

        testPeer.expectTransfer(messageMatcher);
        testPeer.expectClose();

        // send the message
        producer.send(mapMessage);

        assertTrue(mapMessage.isBodyAssignableTo(Map.class));
        assertTrue(mapMessage.isBodyAssignableTo(Object.class));
        assertFalse(mapMessage.isBodyAssignableTo(Boolean.class));
        assertFalse(mapMessage.isBodyAssignableTo(byte[].class));

        assertNotNull(mapMessage.getBody(Object.class));
        assertNotNull(mapMessage.getBody(Map.class));
        try {
            mapMessage.getBody(byte[].class);
            fail("Cannot read TextMessage with this type.");
        } catch (MessageFormatException mfe) {
        }

        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 18
Source File: MapMessageIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 20000)
public void testSendMapMessageIsWritable() 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 myIntKey = "myInt";
        int myInt = Integer.MAX_VALUE;
        String myStringKey = "myString";
        String myString = myStringKey;

        // Prepare a MapMessage to send to the test peer to send
        MapMessage mapMessage = session.createMapMessage();

        mapMessage.setString(myStringKey, myString);

        // prepare a matcher for the test peer to use to receive and verify the message
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        map.put(myStringKey, myString);

        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        msgAnnotationsMatcher.withEntry(AmqpMessageSupport.JMS_MSG_TYPE, equalTo(AmqpMessageSupport.JMS_MAP_MESSAGE));
        MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true);
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(propertiesMatcher);
        messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(map));

        testPeer.expectTransfer(messageMatcher);

        // send the message
        producer.send(mapMessage);

        // Update the message and matcher and send again
        mapMessage.setInt(myIntKey, myInt);
        map.put(myIntKey, myInt);
        testPeer.expectTransfer(messageMatcher);
        testPeer.expectClose();

        producer.send(mapMessage);

        connection.close();

        testPeer.waitForAllHandlersToComplete(3000);
    }
}
 
Example 19
Source File: AmqpManagementFacade.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public Map<String, Object> createEntityAndAssertResponse(final String name,
                                        final String type,
                                        final Map<String, Object> attributes,
                                        final Session session)
        throws JMSException
{
    Destination replyToDestination;
    Destination replyConsumerDestination;
    if (_protocol == Protocol.AMQP_1_0)
    {
        replyToDestination = session.createTemporaryQueue();
        replyConsumerDestination = replyToDestination;
    }
    else
    {
        replyToDestination = session.createQueue(AMQP_0_X_REPLY_TO_DESTINATION);
        replyConsumerDestination = session.createQueue(AMQP_0_X_CONSUMER_REPLY_DESTINATION);
    }

    MessageConsumer consumer = session.createConsumer(replyConsumerDestination);

    MessageProducer producer = session.createProducer(session.createQueue(_managementAddress));

    MapMessage createMessage = session.createMapMessage();
    createMessage.setStringProperty("type", type);
    createMessage.setStringProperty("operation", "CREATE");
    createMessage.setString("name", name);
    createMessage.setString("object-path", name);
    createMessage.setJMSReplyTo(replyToDestination);
    for (Map.Entry<String, Object> entry : attributes.entrySet())
    {
        createMessage.setObject(entry.getKey(), entry.getValue());
    }
    producer.send(createMessage);
    if (session.getTransacted())
    {
        session.commit();
    }
    producer.close();

    return receiveManagementResponse(consumer, replyToDestination, 201);
}
 
Example 20
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@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();
      }
   }
}