use of javax.jms.JMSContext in project brave by openzipkin.
the class ITJms_2_0_TracingMessageConsumer method receive_customSampler.
@Test
public void receive_customSampler() throws JMSException {
queueReceiver.close();
MessagingRuleSampler consumerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).consumerSampler(consumerSampler).build();
JMSContext context = JmsTracing.create(messagingTracing).connectionFactory(((ArtemisJmsTestRule) jms).factory).createContext(JMSContext.AUTO_ACKNOWLEDGE);
JMSConsumer consumer = context.createConsumer(jms.queue)) {
queueSender.send(message);
// Check that the message headers are not sampled
assertThat(consumer.receive().getStringProperty("b3")).endsWith("-0");
}
// @After will also check that the consumer was not sampled
}
use of javax.jms.JMSContext in project brave by openzipkin.
the class ITJms_2_0_TracingMessageProducer method customSampler.
@Test
public void customSampler() throws JMSException {
MessagingRuleSampler producerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).producerSampler(producerSampler).build();
JMSContext context = JmsTracing.create(messagingTracing).connectionFactory(((ArtemisJmsTestRule) jms).factory).createContext(JMSContext.AUTO_ACKNOWLEDGE)) {
context.createProducer().send(jms.queue, "foo");
}
Message received = queueReceiver.receive();
assertThat(propertiesToMap(received)).containsKey("b3").satisfies(m -> assertThat(m.get("b3")).endsWith("-0"));
// @After will also check that the producer was not sampled
}
use of javax.jms.JMSContext in project qpid-broker-j by apache.
the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected.
/**
* 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"));
}
}
}
use of javax.jms.JMSContext in project qpid-broker-j by apache.
the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueue_MessageRejected.
/**
* The target queue, which is addressed directly by the client, does not have
* holdsOnPublish turned on. The Broker must reject the message.
*/
@Test
public void testDeliveryDelayNotSupportedByQueue_MessageRejected() throws Exception {
try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) {
Destination queue = createQueue(context, BrokerAdmin.TEST_QUEUE_NAME, false);
JMSProducer producer = context.createProducer().setDeliveryDelay(DELIVERY_DELAY);
try {
producer.send(queue, "message");
fail("Exception not thrown");
} catch (JMSRuntimeException e) {
assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed"));
}
}
}
use of javax.jms.JMSContext in project quickstart by wildfly.
the class JMSRaceStage method run.
@Override
public void run(Race.Registration registration) throws Exception {
try (JMSContext jmsContext = cf.createContext()) {
// create response tmp queue
final TemporaryQueue responseQueue = jmsContext.createTemporaryQueue();
// send request
final String request = UUID.randomUUID().toString();
jmsContext.createProducer().setJMSReplyTo(responseQueue).send(requestQueue, request);
// receive response
try (JMSConsumer consumer = jmsContext.createConsumer(responseQueue)) {
String response = consumer.receiveBody(String.class);
if (response == null) {
registration.aborted(new IllegalStateException("Message processing timed out"));
} else if (!response.equals(request)) {
registration.aborted(new IllegalStateException("Response content does not match the request. Response: " + response + ", request: " + request));
}
}
}
}
Aggregations