javax.jms.JMSProducer Java Examples
The following examples show how to use
javax.jms.JMSProducer.
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: JMSContextIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testOnlyOneProducerCreatedInSingleContext() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, SERVER_ANONYMOUS_RELAY); assertEquals(JMSContext.AUTO_ACKNOWLEDGE, context.getSessionMode()); testPeer.expectBegin(); testPeer.expectSenderAttach(); // One producer created should send an attach. JMSProducer producer1 = context.createProducer(); assertNotNull(producer1); // An additional one should not result in an attach JMSProducer producer2 = context.createProducer(); assertNotNull(producer2); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #2
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testMapBodyIsApplied() throws JMSException { JMSProducer producer = context.createProducer(); final Map<String, Object> bodyValue = new HashMap<String, Object>(); bodyValue.put("Value-1", "First"); bodyValue.put("Value-2", "Second"); final AtomicBoolean bodyValidated = new AtomicBoolean(); MockJMSConnection connection = (MockJMSConnection) context.getConnection(); connection.addConnectionListener(new MockJMSDefaultConnectionListener() { @Override public void onMessageSend(MockJMSSession session, Message message) throws JMSException { assertEquals(bodyValue, message.getBody(Map.class)); bodyValidated.set(true); } }); producer.send(JMS_DESTINATION, bodyValue); assertTrue(bodyValidated.get()); }
Example #3
Source File: JmsSourceTest.java From smallrye-reactive-messaging with Apache License 2.0 | 6 votes |
@Test public void testReceptionOfMultipleMessages() { WeldContainer container = prepare(); RawMessageConsumerBean bean = container.select(RawMessageConsumerBean.class).get(); assertThat(bean.messages()).isEmpty(); Queue q = jms.createQueue("queue-one"); JMSProducer producer = jms.createProducer(); new Thread(() -> { for (int i = 0; i < 50; i++) { TextMessage message = jms.createTextMessage(Integer.toString(i)); producer.send(q, message); } }).start(); await().until(() -> bean.messages().size() == 50); }
Example #4
Source File: JMSProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testJMSProducerHasDefaultConfiguration() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JMSContext context = testFixture.createJMSContext(testPeer, SERVER_ANONYMOUS_RELAY); testPeer.expectBegin(); testPeer.expectSenderAttach(); JMSProducer producer = context.createProducer(); assertNotNull(producer); assertEquals(Message.DEFAULT_DELIVERY_DELAY, producer.getDeliveryDelay()); assertEquals(Message.DEFAULT_DELIVERY_MODE, producer.getDeliveryMode()); assertEquals(Message.DEFAULT_PRIORITY, producer.getPriority()); assertEquals(Message.DEFAULT_TIME_TO_LIVE, producer.getTimeToLive()); testPeer.expectEnd(); testPeer.expectClose(); context.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #5
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 6 votes |
@Test public void testRuntimeExceptionFromSendMapBody() throws JMSException { JMSProducer producer = context.createProducer(); MockJMSConnection connection = (MockJMSConnection) context.getConnection(); connection.addConnectionListener(new MockJMSDefaultConnectionListener() { @Override public void onMessageSend(MockJMSSession session, Message message) throws JMSException { throw new IllegalStateException("Send Failed"); } }); try { producer.send(context.createTemporaryQueue(), Collections.<String, Object>emptyMap()); fail("Should have thrown an exception"); } catch (IllegalStateRuntimeException isre) {} }
Example #6
Source File: JmsContext.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override public JMSProducer createProducer() { try { if (sharedProducer == null) { synchronized (this) { if (sharedProducer == null) { sharedProducer = (JmsMessageProducer) getSession().createProducer(null); } } } return new JmsProducer(getSession(), sharedProducer); } catch (JMSException jmse) { throw JmsExceptionSupport.createRuntimeException(jmse); } }
Example #7
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testBytesBodyIsApplied() throws JMSException { JMSProducer producer = context.createProducer(); final byte[] bodyValue = new byte[] { 0, 1, 2, 3, 4 }; producer.send(JMS_DESTINATION, bodyValue); JmsOutboundMessageDispatch envelope = remotePeer.getLastReceivedMessage(); assertNotNull(envelope); JmsMessage message = envelope.getMessage(); byte[] payload = message.getBody(byte[].class); assertNotNull(payload); assertEquals(bodyValue.length, payload.length); for (int i = 0; i < payload.length; ++i) { assertEquals(bodyValue[i], payload[i]); } }
Example #8
Source File: OutgoingConnectionJTATest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testSimpleSendNoXAJMSContext() throws Exception { Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(); ClientConsumer consVerify = session.createConsumer(MDBQUEUE); JMSContext jmsctx = qraConnectionFactory.createContext(); ) { session.start(); // These next 4 lines could be written in a single line however it makes difficult for debugging JMSProducer producer = jmsctx.createProducer(); producer.setProperty("strvalue", "hello"); TextMessage msgsend = jmsctx.createTextMessage("hello"); producer.send(q, msgsend); ClientMessage msg = consVerify.receive(1000); assertNotNull(msg); assertEquals("hello", msg.getStringProperty("strvalue")); } }
Example #9
Source File: MockJMSProducer.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(Destination destination, Message message) { try { doSend(destination, message); } catch (JMSException jmse) { throw JMSExceptionSupport.createRuntimeException(jmse); } return this; }
Example #10
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSetIntPropertyWithBadPropertyName() { JMSProducer producer = context.createProducer(); try { producer.setProperty(BAD_PROPERTY_NAME, 100); fail("Should not accept invalid property name"); } catch (IllegalArgumentException iae) {} }
Example #11
Source File: JMSProducerImpl.java From tomee with Apache License 2.0 | 5 votes |
@Override public JMSProducer setJMSCorrelationIDAsBytes(final byte[] correlationID) { if (correlationID == null || correlationID.length == 0) { throw new JMSRuntimeException("Please specify a non-zero length byte[]"); } jmsHeaderCorrelationIDAsBytes = Arrays.copyOf(correlationID, correlationID.length); return this; }
Example #12
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSendNullMessageThrowsMFRE() throws JMSException { JMSProducer producer = context.createProducer(); try { producer.send(JMS_DESTINATION, (Message) null); fail("Should throw a MessageFormatRuntimeException"); } catch (MessageFormatRuntimeException mfre) { } catch (Exception e) { fail("Should throw a MessageFormatRuntimeException"); } }
Example #13
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testPriority() { JMSProducer producer = context.createProducer(); producer.setPriority(1); assertEquals(1, producer.getPriority()); producer.setPriority(4); assertEquals(4, producer.getPriority()); }
Example #14
Source File: DeliveryDelayTest.java From qpid-broker-j with Apache License 2.0 | 5 votes |
/** * The client sends a messagge to a fanout exchange instance which is bound to a queue with * holdsOnPublish turned off. The Broker must reject the message. */ @Test public void testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected() throws Exception { try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) { String testQueueName = BrokerAdmin.TEST_QUEUE_NAME; String testExchangeName = "test_exch"; Destination consumeDest = createQueue(context, testQueueName, false); Destination publishDest = createExchange(context, testExchangeName); bindQueueToExchange(testExchangeName, testQueueName); JMSConsumer consumer = context.createConsumer(consumeDest); JMSProducer producer = context.createProducer(); producer.send(publishDest, "message without delivery delay"); Message message = consumer.receive(getReceiveTimeout()); assertNotNull("Message published without delivery delay not received", message); producer.setDeliveryDelay(DELIVERY_DELAY); try { producer.send(publishDest, "message with delivery delay"); fail("Exception not thrown"); } catch (JMSRuntimeException e) { assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed")); } } }
Example #15
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testSetBooleanPropetryWithBadPropetyName() { JMSProducer producer = context.createProducer(); try { producer.setProperty(BAD_PROPERTY_NAME, true); fail("Should not accept invalid property name"); } catch (IllegalArgumentException iae) {} }
Example #16
Source File: ActiveMQJMSProducer.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public JMSProducer setProperty(String name, String value) { checkName(name); SimpleString key = new SimpleString(name); properties.putSimpleStringProperty(key, new SimpleString(value)); stringPropertyNames.add(key); return this; }
Example #17
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testClearProperties() { JMSProducer producer = context.createProducer(); producer.setProperty("Property_1", "1"); producer.setProperty("Property_2", "2"); producer.setProperty("Property_3", "3"); assertEquals(3, producer.getPropertyNames().size()); producer.clearProperties(); assertEquals(0, producer.getPropertyNames().size()); }
Example #18
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSetBytePropertyWithBadPropertyName() { JMSProducer producer = context.createProducer(); try { producer.setProperty(BAD_PROPERTY_NAME, (byte) 1); fail("Should not accept invalid property name"); } catch (IllegalArgumentException iae) {} }
Example #19
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSetFloatPropertyWithBadPropertyName() { JMSProducer producer = context.createProducer(); try { producer.setProperty(BAD_PROPERTY_NAME, 100.0f); fail("Should not accept invalid property name"); } catch (IllegalArgumentException iae) {} }
Example #20
Source File: JmsProducerTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testGetPropertyNames() { JMSProducer producer = context.createProducer(); producer.setProperty("Property_1", "1"); producer.setProperty("Property_2", "2"); producer.setProperty("Property_3", "3"); assertEquals(3, producer.getPropertyNames().size()); assertTrue(producer.getPropertyNames().contains("Property_1")); assertTrue(producer.getPropertyNames().contains("Property_2")); assertTrue(producer.getPropertyNames().contains("Property_3")); }
Example #21
Source File: JmsProducer.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer setPriority(int priority) { if (priority < 0 || priority > 9) { throw new JMSRuntimeException(String.format("Priority value given {%d} is out of range (0..9)", priority)); } this.priority = priority; return this; }
Example #22
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSetStringPropertyWithBadPropertyName() { JMSProducer producer = context.createProducer(); try { producer.setProperty(BAD_PROPERTY_NAME, "X"); fail("Should not accept invalid property name"); } catch (IllegalArgumentException iae) {} }
Example #23
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testSetPropertyConversions() { JMSProducer producer = context.createProducer(); producer.setProperty(STRING_PROPERTY_NAME, STRING_PROPERTY_VALUE); producer.setProperty(BYTE_PROPERTY_NAME, Byte.valueOf(BYTE_PROPERTY_VALUE)); producer.setProperty(BOOLEAN_PROPERTY_NAME, Boolean.valueOf(BOOLEAN_PROPERTY_VALUE)); producer.setProperty(SHORT_PROPERTY_NAME, Short.valueOf(SHORT_PROPERTY_VALUE)); producer.setProperty(INTEGER_PROPERTY_NAME, Integer.valueOf(INTEGER_PROPERTY_VALUE)); producer.setProperty(LONG_PROPERTY_NAME, Long.valueOf(LONG_PROPERTY_VALUE)); producer.setProperty(FLOAT_PROPERTY_NAME, Float.valueOf(FLOAT_PROPERTY_VALUE)); producer.setProperty(DOUBLE_PROPERTY_NAME, Double.valueOf(DOUBLE_PROPERTY_VALUE)); try { producer.setProperty(STRING_PROPERTY_NAME, UUID.randomUUID()); fail("Should not be able to set non-primitive type"); } catch (MessageFormatRuntimeException mfe) { } assertNull(producer.getObjectProperty("Unknown")); assertEquals(STRING_PROPERTY_VALUE, producer.getStringProperty(STRING_PROPERTY_NAME)); assertEquals(BYTE_PROPERTY_VALUE, producer.getByteProperty(BYTE_PROPERTY_NAME)); assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getBooleanProperty(BOOLEAN_PROPERTY_NAME)); assertEquals(SHORT_PROPERTY_VALUE, producer.getShortProperty(SHORT_PROPERTY_NAME)); assertEquals(INTEGER_PROPERTY_VALUE, producer.getIntProperty(INTEGER_PROPERTY_NAME)); assertEquals(LONG_PROPERTY_VALUE, producer.getLongProperty(LONG_PROPERTY_NAME)); assertEquals(FLOAT_PROPERTY_VALUE, producer.getFloatProperty(FLOAT_PROPERTY_NAME), 0.0); assertEquals(DOUBLE_PROPERTY_VALUE, producer.getDoubleProperty(DOUBLE_PROPERTY_NAME), 0.0); assertEquals(STRING_PROPERTY_VALUE, producer.getObjectProperty(STRING_PROPERTY_NAME)); assertEquals(BYTE_PROPERTY_VALUE, producer.getObjectProperty(BYTE_PROPERTY_NAME)); assertEquals(BOOLEAN_PROPERTY_VALUE, producer.getObjectProperty(BOOLEAN_PROPERTY_NAME)); assertEquals(SHORT_PROPERTY_VALUE, producer.getObjectProperty(SHORT_PROPERTY_NAME)); assertEquals(INTEGER_PROPERTY_VALUE, producer.getObjectProperty(INTEGER_PROPERTY_NAME)); assertEquals(LONG_PROPERTY_VALUE, producer.getObjectProperty(LONG_PROPERTY_NAME)); assertEquals(FLOAT_PROPERTY_VALUE, producer.getObjectProperty(FLOAT_PROPERTY_NAME)); assertEquals(DOUBLE_PROPERTY_VALUE, producer.getObjectProperty(DOUBLE_PROPERTY_NAME)); }
Example #24
Source File: JMSProducerImpl.java From tomee with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(final Destination destination, final byte[] body) { final BytesMessage message = wrap(context.createBytesMessage()); if (body != null) { try { message.writeBytes(body); } catch (final JMSException e) { throw new MessageFormatRuntimeException(e.getMessage()); } } send(destination, message); return this; }
Example #25
Source File: JmsProducer.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer send(Destination destination, String body) { try { TextMessage message = session.createTextMessage(body); doSend(destination, message); } catch (JMSException jmse) { throw JmsExceptionSupport.createRuntimeException(jmse); } return this; }
Example #26
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testJMSType() { JMSProducer producer = context.createProducer(); producer.setJMSType(JMS_TYPE_STRING); assertEquals(JMS_TYPE_STRING, producer.getJMSType()); }
Example #27
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testJMSCorrelationIDBytes() { JMSProducer producer = context.createProducer(); producer.setJMSCorrelationIDAsBytes(JMS_CORRELATION_ID.getBytes(StandardCharsets.UTF_8)); assertEquals(JMS_CORRELATION_ID, new String(producer.getJMSCorrelationIDAsBytes(), StandardCharsets.UTF_8)); }
Example #28
Source File: JmsPoolJMSProducerTest.java From pooled-jms with Apache License 2.0 | 5 votes |
@Test public void testGetPropertyNames() { JMSProducer producer = context.createProducer(); producer.setProperty("Property_1", "1"); producer.setProperty("Property_2", "2"); producer.setProperty("Property_3", "3"); assertEquals(3, producer.getPropertyNames().size()); assertTrue(producer.getPropertyNames().contains("Property_1")); assertTrue(producer.getPropertyNames().contains("Property_2")); assertTrue(producer.getPropertyNames().contains("Property_3")); }
Example #29
Source File: JmsPoolJMSProducer.java From pooled-jms with Apache License 2.0 | 5 votes |
@Override public JMSProducer setPriority(int priority) { if (priority < 0 || priority > 9) { throw new JMSRuntimeException(String.format("Priority value given {%d} is out of range (0..9)", priority)); } this.priority = priority; return this; }
Example #30
Source File: JMSProducerImpl.java From tomee with Apache License 2.0 | 5 votes |
@Override public JMSProducer setDeliveryDelay(final long deliveryDelay) { try { producer.setDeliveryDelay(deliveryDelay); return this; } catch (final JMSException e) { JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage()); e2.initCause(e); throw e2; } }