Java Code Examples for javax.jms.MapMessage#setBoolean()
The following examples show how to use
javax.jms.MapMessage#setBoolean() .
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: JMSPublisher.java From product-microgateway with Apache License 2.0 | 6 votes |
public void publishMessage(String msg) throws NamingException, JMSException { String topicName = "throttleData"; InitialContext initialContext = ClientHelper.getInitialContextBuilder("admin", "admin", "localhost", "5672") .withTopic(topicName) .build(); ConnectionFactory connectionFactory = (ConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY); Connection connection = connectionFactory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic) initialContext.lookup(topicName); MessageProducer producer = session.createProducer(topic); MapMessage mapMessage = session.createMapMessage(); mapMessage.setString("throttleKey", msg); Date date = new Date(); long time = date.getTime() + 1000; mapMessage.setLong("expiryTimeStamp", time); mapMessage.setBoolean("isThrottled", true); producer.send(mapMessage); connection.close(); }
Example 2
Source File: ConsumeJMSManualTest.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testMapMessage() throws Exception { MessageCreator messageCreator = session -> { MapMessage message = session.createMapMessage(); message.setBoolean("boolean", true); message.setByte("byte", Integer.valueOf(1).byteValue()); message.setBytes("bytes", new byte[] {2, 3, 4}); message.setShort("short", (short)32); message.setInt("int", 64); message.setLong("long", 128L); message.setFloat("float", 1.25F); message.setDouble("double", 100.867); message.setChar("char", 'c'); message.setString("string", "someString"); message.setObject("object", "stringAsObject"); return message; }; send(messageCreator); }
Example 3
Source File: JmsProduceMessageTypesTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 60000) public void testSendJMSMapMessage() throws Exception { connection = createAmqpConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(session); Queue queue = session.createQueue(name.getMethodName()); MessageProducer producer = session.createProducer(queue); MapMessage message = session.createMapMessage(); message.setBoolean("Boolean", false); message.setString("STRING", "TEST"); producer.send(message); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(1, proxy.getQueueSize()); MessageConsumer consumer = session.createConsumer(queue); Message received = consumer.receive(5000); assertNotNull(received); assertTrue(received instanceof MapMessage); MapMessage map = (MapMessage) received; assertEquals("TEST", map.getString("STRING")); assertEquals(false, map.getBooleanProperty("Boolean")); }
Example 4
Source File: MapMessageTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override protected void prepareMessage(final Message m) throws JMSException { super.prepareMessage(m); MapMessage mm = (MapMessage) m; 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"); }
Example 5
Source File: MessageCompressionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 6
Source File: GeneralInteropTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
private void sendMapMessageUsingOpenWire() 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("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); }
Example 7
Source File: CompressedInteropTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
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 8
Source File: GeneralInteropTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
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 9
Source File: ReSendMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 10
Source File: ReSendMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@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 11
Source File: ActiveMQJMSProducer.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(Destination destination, Map<String, Object> body) { MapMessage message = context.createMapMessage(); if (body != null) { try { for (Entry<String, Object> entry : body.entrySet()) { final String name = entry.getKey(); final Object v = entry.getValue(); if (v instanceof String) { message.setString(name, (String) v); } else if (v instanceof Long) { message.setLong(name, (Long) v); } else if (v instanceof Double) { message.setDouble(name, (Double) v); } else if (v instanceof Integer) { message.setInt(name, (Integer) v); } else if (v instanceof Character) { message.setChar(name, (Character) v); } else if (v instanceof Short) { message.setShort(name, (Short) v); } else if (v instanceof Boolean) { message.setBoolean(name, (Boolean) v); } else if (v instanceof Float) { message.setFloat(name, (Float) v); } else if (v instanceof Byte) { message.setByte(name, (Byte) v); } else if (v instanceof byte[]) { byte[] array = (byte[]) v; message.setBytes(name, array, 0, array.length); } else { message.setObject(name, v); } } } catch (JMSException e) { throw new MessageFormatRuntimeException(e.getMessage()); } } send(destination, message); return this; }
Example 12
Source File: MapMessageTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private void setMapValues(MapMessage message) throws JMSException { message.setBoolean("bool", true); message.setByte("byte",Byte.MAX_VALUE); message.setBytes("bytes", BYTES); message.setChar("char",'c'); message.setDouble("double", Double.MAX_VALUE); message.setFloat("float", Float.MAX_VALUE); message.setFloat("smallfloat", SMALL_FLOAT); message.setInt("int", Integer.MAX_VALUE); message.setLong("long", Long.MAX_VALUE); message.setShort("short", Short.MAX_VALUE); message.setString("string-ascii", MESSAGE_ASCII); message.setString("string-utf8", MESSAGE_NON_ASCII_UTF8); // Test Setting Object Values message.setObject("object-bool", true); message.setObject("object-byte", Byte.MAX_VALUE); message.setObject("object-bytes", BYTES); message.setObject("object-char", 'c'); message.setObject("object-double", Double.MAX_VALUE); message.setObject("object-float", Float.MAX_VALUE); message.setObject("object-int", Integer.MAX_VALUE); message.setObject("object-long", Long.MAX_VALUE); message.setObject("object-short", Short.MAX_VALUE); // Set a null String value message.setString("nullString", null); // Highlight protocol problem message.setString("emptyString", ""); }
Example 13
Source File: TestJmsConsumer.java From nifi with Apache License 2.0 | 5 votes |
static protected MapMessage createMapMessage() throws JMSException { MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString("name", "Arnold"); mapMessage.setInt("age", 97); mapMessage.setDouble("xyz", 89686.564); mapMessage.setBoolean("good", true); return mapMessage; }
Example 14
Source File: JMSPublisherConsumerIT.java From nifi with Apache License 2.0 | 5 votes |
@Test public void testMapMessage() throws Exception { final String destinationName = "testObjectMessage"; MessageCreator messageCreator = session -> { MapMessage message = session.createMapMessage(); message.setBoolean("boolean", true); message.setByte("byte", Integer.valueOf(1).byteValue()); message.setBytes("bytes", new byte[] {2, 3, 4}); message.setShort("short", (short)32); message.setInt("int", 64); message.setLong("long", 128L); message.setFloat("float", 1.25F); message.setDouble("double", 100.867); message.setChar("char", 'c'); message.setString("string", "someString"); message.setObject("object", "stringAsObject"); return message; }; String expectedJson = "{" + "\"boolean\":true," + "\"byte\":1," + "\"bytes\":[2, 3, 4]," + "\"short\":32," + "\"int\":64," + "\"long\":128," + "\"float\":1.25," + "\"double\":100.867," + "\"char\":\"c\"," + "\"string\":\"someString\"," + "\"object\":\"stringAsObject\"" + "}"; testMapMessage(destinationName, messageCreator, expectedJson); }
Example 15
Source File: TestJmsConsumer.java From localization_nifi with Apache License 2.0 | 5 votes |
static protected MapMessage createMapMessage() throws JMSException { MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString("name", "Arnold"); mapMessage.setInt("age", 97); mapMessage.setDouble("xyz", 89686.564); mapMessage.setBoolean("good", true); return mapMessage; }
Example 16
Source File: JMSProducerImpl.java From tomee with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(final Destination destination, final Map<String, Object> body) { final MapMessage message = wrap(context.createMapMessage()); if (body != null) { try { for (final Map.Entry<String, Object> entry : body.entrySet()) { final String name = entry.getKey(); final Object v = entry.getValue(); if (v instanceof String) { message.setString(name, (String) v); } else if (v instanceof Long) { message.setLong(name, (Long) v); } else if (v instanceof Double) { message.setDouble(name, (Double) v); } else if (v instanceof Integer) { message.setInt(name, (Integer) v); } else if (v instanceof Character) { message.setChar(name, (Character) v); } else if (v instanceof Short) { message.setShort(name, (Short) v); } else if (v instanceof Boolean) { message.setBoolean(name, (Boolean) v); } else if (v instanceof Float) { message.setFloat(name, (Float) v); } else if (v instanceof Byte) { message.setByte(name, (Byte) v); } else if (v instanceof byte[]) { byte[] array = (byte[]) v; message.setBytes(name, array, 0, array.length); } else { message.setObject(name, v); } } } catch (final JMSException e) { throw new MessageFormatRuntimeException(e.getMessage()); } } send(destination, message); return this; }
Example 17
Source File: SuccessMessage.java From chipster with MIT License | 5 votes |
public void marshal(MapMessage mapMessage) throws JMSException { super.marshal(mapMessage); mapMessage.setBoolean(KEY_SUCCESS, success); mapMessage.setString(KEY_ERROR_MESSAGE, this.errorMessage); mapMessage.setString(KEY_DETAILS, this.details); if (this.exception != null) { mapMessage.setString(KEY_EXCEPTION, this.exception.getMessage() + Exceptions.getStackTrace(this.exception)); } }
Example 18
Source File: MapMessageIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@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); } }