Java Code Examples for javax.jms.MapMessage#setString()
The following examples show how to use
javax.jms.MapMessage#setString() .
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: JMSUtilsTest.java From micro-integrator with Apache License 2.0 | 6 votes |
/** * Test ConvertJMSMapToXML * * @throws Exception */ @Test public void testConvertJMSMapToXML() throws Exception { String queueName = "testHandler"; Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, false); JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties); try { brokerController.startProcess(); brokerController.connect(queueName, true); MapMessage mapMessage = brokerController.createMapMessage(); mapMessage.setStringProperty("MessageFormat", "Person"); mapMessage.setString("NAME", queueName); mapMessage.setInt("COUNT", 10); mapMessage.setDouble("PRICE", 12.00); OMElement result = JMSInjectHandler.convertJMSMapToXML(mapMessage); Assert.assertEquals("The converted XML is not correct", "10", ((OMElement) result. getChildrenWithLocalName("COUNT").next()).getText()); Assert.assertEquals("The converted XML is not correct", queueName, ((OMElement) result. getChildrenWithLocalName("NAME").next()).getText()); } finally { brokerController.stopProcess(); } }
Example 2
Source File: MessageSerializerTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testMapMessageImportExport() throws Exception { String address = "test"; String key = "testKey"; File file = createMessageFile(); Session session = createSession(connection); List<Message> sent = new ArrayList<>(TEST_MESSAGE_COUNT); for (int i = 0; i < TEST_MESSAGE_COUNT; i++) { MapMessage m = session.createMapMessage(); m.setString(key, RandomUtil.randomString()); sent.add(m); } sendMessages(session, getDestination(address), sent); exportMessages(address, file); Wait.assertTrue(() -> verifyMessageCount(address, 0), 2000, 100); importMessages(address, file); Wait.assertTrue(() -> verifyMessageCount(address, TEST_MESSAGE_COUNT), 2000, 100); checkSentMessages(session, sent, address, key); }
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: TestGetJMSQueue.java From nifi with Apache License 2.0 | 6 votes |
@org.junit.Ignore public void testSendMapToQueue() throws Exception { final TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class); runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER); runner.setProperty(JmsProperties.URL, "tcp://localhost:61616"); runner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE); runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing"); runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO); WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(runner.getProcessContext(), true); final Session jmsSession = wrappedProducer.getSession(); final MessageProducer producer = wrappedProducer.getProducer(); final MapMessage message = jmsSession.createMapMessage(); message.setString("foo!", "bar"); message.setString("bacon", "meat"); producer.send(message); jmsSession.commit(); producer.close(); jmsSession.close(); }
Example 5
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 6
Source File: ParameterMessage.java From chipster with MIT License | 6 votes |
@Override public void marshal(MapMessage to) throws JMSException { super.marshal(to); // add parameters int i = 0; for (String parameter : parameters) { logger.debug("populated map message with " + KEY_PARAMETER + i + ": " + new String(parameter)); to.setString(KEY_PARAMETER + i, parameter); i++; } // add named parameters logger.debug("Marshalling named parameters: " + namedParameters.keySet()); int j = 0; for (String key : namedParameters.keySet()) { to.setString(KEY_NAMED_PARAMETER_KEY + j, key); to.setString(KEY_NAMED_PARAMETER_VALUE + j, namedParameters.get(key)); j++; } }
Example 7
Source File: MessageTypeTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Send a <code>MapMessage</code> with 2 Java primitives in its body (a <code> * String</code> and a <code>double</code>). * <br /> * Receive it and test that the values of the primitives of the body are correct */ @Test public void testMapMessage_2() { try { MapMessage message = senderSession.createMapMessage(); message.setString("name", "pi"); message.setDouble("value", 3.14159); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); Assert.assertTrue("The message should be an instance of MapMessage.\n", m instanceof MapMessage); MapMessage msg = (MapMessage) m; Assert.assertEquals("pi", msg.getString("name")); Assert.assertEquals(3.14159, msg.getDouble("value"), 0); } catch (JMSException e) { fail(e); } }
Example 8
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 9
Source File: AmqpManagementTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
@Test public void testCreateQueueWithQpidType() throws Exception { assumeThat(isSupportedClient(), is(true)); Connection connection = getConnection(); try { setUp(connection); MapMessage message = _session.createMapMessage(); message.setStringProperty("type", "org.apache.qpid.Queue"); message.setStringProperty("operation", "CREATE"); message.setString("name", getTestName()); message.setString("qpid-type", "lvq"); String path = getTestName(); message.setString("object-path", path); message.setJMSReplyTo(_replyAddress); _producer.send(message); Message responseMessage = _consumer.receive(getReceiveTimeout()); assertResponseCode(responseMessage, 201); checkResponseIsMapType(responseMessage); assertEquals("The created queue did not have the correct type", "org.apache.qpid.LastValueQueue", getValueFromMapResponse(responseMessage, "type")); } finally { connection.close(); } }
Example 10
Source File: ResultMessage.java From chipster with MIT License | 5 votes |
public void marshal(MapMessage mapMessage) throws JMSException { super.marshal(mapMessage); mapMessage.setString(KEY_JOB_ID, this.jobId); mapMessage.setString(KEY_STATE, this.state.name()); mapMessage.setString(KEY_STATE_DETAIL, this.stateDetail); mapMessage.setString(KEY_ERROR_MESSAGE, this.errorMessage); mapMessage.setString(KEY_OUTPUT_TEXT, this.outputText); mapMessage.setString(KEY_SOURCE_CODE, this.sourceCode); }
Example 11
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 12
Source File: SampleMessageConverter.java From tutorials with MIT License | 5 votes |
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 13
Source File: JobMessage.java From chipster with MIT License | 5 votes |
/** * Construct a MapMessage that can be used to create a new JobMessage. */ @Override public void marshal(MapMessage mapMessage) throws JMSException { super.marshal(mapMessage); logger.debug("Marshalling: " + KEY_JOB_ID + " : " + this.jobId); logger.debug("Marshalling: " + KEY_TOOL_ID + " : " + this.toolId); // add ids mapMessage.setString(KEY_JOB_ID, this.jobId); mapMessage.setString(KEY_TOOL_ID, this.toolId); }
Example 14
Source File: InactiveQueueTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testNoSubscribers() throws Exception { connection = connectionFactory.createConnection(USERNAME, DEFAULT_PASSWORD); assertNotNull(connection); connection.start(); session = connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); assertNotNull(session); destination = session.createQueue(QUEUE_NAME); assertNotNull(destination); publisher = session.createProducer(destination); assertNotNull(publisher); MapMessage msg = session.createMapMessage(); assertNotNull(msg); msg.setString("key1", "value1"); int loop; for (loop = 0; loop < MESSAGE_COUNT; loop++) { msg.setInt("key2", loop); publisher.send(msg, DELIVERY_MODE, DELIVERY_PRIORITY, Message.DEFAULT_TIME_TO_LIVE); if (loop % 500 == 0) { LOG.debug("Sent " + loop + " messages"); } } Thread.sleep(1000000); assertEquals(loop, MESSAGE_COUNT); publisher.close(); session.close(); connection.stop(); connection.stop(); }
Example 15
Source File: SourceMessage.java From chipster with MIT License | 4 votes |
public void marshal(MapMessage mapMessage) throws JMSException { super.marshal(mapMessage); mapMessage.setString(KEY_SOURCE, source); }
Example 16
Source File: BodyIsAssignableFromTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * @param type * @throws JMSException */ private Object createBodySendAndReceive(JmsMessageType type) throws JMSException { Object res = null; Message msg = null; switch (type) { case BYTE: BytesMessage mByte = queueProducerSession.createBytesMessage(); final int size = 20; byte[] resByte = new byte[size]; for (int i = 0; i < size; i++) { resByte[i] = (byte) i; mByte.writeByte((byte) i); } msg = mByte; res = resByte; break; case TEXT: res = "JMS2"; msg = queueProducerSession.createTextMessage("JMS2"); break; case STREAM: msg = queueProducerSession.createStreamMessage(); break; case OBJECT: res = new Double(37.6); msg = queueProducerSession.createObjectMessage(new Double(37.6)); break; case MAP: MapMessage msg1 = queueProducerSession.createMapMessage(); msg1.setInt("int", 13); msg1.setLong("long", 37L); msg1.setString("string", "crocodile"); msg = msg1; Map<String, Object> map = new HashMap<>(); map.put("int", Integer.valueOf(13)); map.put("long", Long.valueOf(37L)); map.put("string", "crocodile"); res = map; break; default: Assert.fail("no default..."); } Assert.assertNotNull(msg); msg.setStringProperty("type", type.toString()); queueProducer.send(msg); return res; }
Example 17
Source File: AmqpManagementTest.java From qpid-broker-j with Apache License 2.0 | 4 votes |
@Test public void testCreateQueueOnBrokerManagement() throws Exception { assumeThat(isSupportedClient(), is(true)); Connection connection = getBrokerManagementConnection(); try { setUp(connection); MapMessage message = _session.createMapMessage(); message.setStringProperty("type", "org.apache.qpid.Queue"); message.setStringProperty("operation", "CREATE"); message.setString("name", getTestName()); message.setLong(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 100L); String path = getVirtualHostName() + "/" + getVirtualHostName() + "/" + getTestName(); message.setString("object-path", path); message.setJMSReplyTo(_replyAddress); _producer.send(message); Message responseMessage = _consumer.receive(getReceiveTimeout()); assertResponseCode(responseMessage, 201); checkResponseIsMapType(responseMessage); assertEquals("The created queue was not a standard queue", "org.apache.qpid.StandardQueue", getValueFromMapResponse(responseMessage, "type")); assertEquals("The created queue was not a standard queue", "standard", getValueFromMapResponse(responseMessage, "qpid-type")); assertEquals("the created queue did not have the correct alerting threshold", 100L, getValueFromMapResponse(responseMessage, ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES)); Object identity = getValueFromMapResponse(responseMessage, "identity"); message = _session.createMapMessage(); message.setStringProperty("type", "org.apache.qpid.Queue"); message.setStringProperty("operation", "UPDATE"); message.setObjectProperty("identity", identity); message.setLong(ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES, 250L); message.setJMSReplyTo(_replyAddress); _producer.send(message); responseMessage = _consumer.receive(getReceiveTimeout()); assertResponseCode(responseMessage, 200); checkResponseIsMapType(responseMessage); assertEquals("the created queue did not have the correct alerting threshold", 250L, getValueFromMapResponse(responseMessage, ALERT_THRESHOLD_QUEUE_DEPTH_MESSAGES)); message = _session.createMapMessage(); message.setStringProperty("type", "org.apache.qpid.Queue"); message.setStringProperty("operation", "DELETE"); message.setObjectProperty("index", "object-path"); message.setObjectProperty("key", path); message.setJMSReplyTo(_replyAddress); _producer.send(message); responseMessage = _consumer.receive(getReceiveTimeout()); assertResponseCode(responseMessage, 204); message = _session.createMapMessage(); message.setStringProperty("type", "org.apache.qpid.Queue"); message.setStringProperty("operation", "READ"); message.setObjectProperty("identity", identity); message.setJMSReplyTo(_replyAddress); _producer.send(message); responseMessage = _consumer.receive(getReceiveTimeout()); assertResponseCode(responseMessage, 404); } finally { connection.close(); } }
Example 18
Source File: ModuleDescriptionMessage.java From chipster with MIT License | 4 votes |
@Override public void marshal(MapMessage to) throws JMSException { super.marshal(to); to.setStringProperty(KEY_MODULE_NAME, this.getModuleName()); to.setString(KEY_MODULE, XmlUtil.xmlToString(moduleXml)); }
Example 19
Source File: CommandMessage.java From chipster with MIT License | 4 votes |
@Override public void marshal(MapMessage to) throws JMSException { super.marshal(to); to.setString(KEY_COMMAND, command); }
Example 20
Source File: SpringJmsTest.java From apm-agent-java with Apache License 2.0 | 4 votes |
@Test public void testSendListenSpringQueue() throws JMSException, InterruptedException { reporter.reset(); try (Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) { Transaction transaction = tracer.startRootTransaction(null).activate(); transaction.withName("JMS-Spring-Test Transaction"); transaction.withType("request"); transaction.withResult("success"); final String key1 = "key1"; final String key2 = "key2"; final String value1 = UUID.randomUUID().toString(); final String value2 = UUID.randomUUID().toString(); MapMessage mapMessage = new ActiveMQMapMessage(); mapMessage.setString(key1, value1); mapMessage.setString(key2, value2); Queue queue = session.createQueue(SPRING_TEST_QUEUE); MessageProducer producer = session.createProducer(queue); producer.send(mapMessage); // Let the onMessage instrumentation end the transaction then end the base transaction Thread.sleep(500); transaction.deactivate().end(); Map result = resultQueue.poll(1, TimeUnit.SECONDS); assertThat(result).isNotNull(); assertThat(result.size()).isEqualTo(2); assertThat(result.get(key1).toString()).isEqualTo(value1); assertThat(result.get(key2).toString()).isEqualTo(value2); List<Transaction> transactions = reporter.getTransactions(); assertThat(transactions).hasSize(2); Transaction baseTransaction = transactions.get(1); Id traceId = baseTransaction.getTraceContext().getTraceId(); List<Span> spans = reporter.getSpans(); assertThat(spans).hasSize(1); Span sendSpan = spans.get(0); assertThat(sendSpan.getNameAsString()).isEqualTo("JMS SEND to queue " + SPRING_TEST_QUEUE); assertThat(sendSpan.getTraceContext().getTraceId()).isEqualTo(traceId); Transaction receiveTransaction = transactions.get(0); verifyReceiveTransaction(traceId, sendSpan, receiveTransaction); } }