Search in sources :

Example 1 with MessagingRuleSampler

use of brave.messaging.MessagingRuleSampler in project brave by openzipkin.

the class ITJms_1_1_TracingMessageConsumer method receive_customSampler.

@Test
public void receive_customSampler() throws JMSException {
    queueReceiver.close();
    tracedSession.close();
    MessagingRuleSampler consumerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).consumerSampler(consumerSampler).build()) {
        // JMS 1.1 didn't have auto-closeable. tearDownTraced closes these
        tracedQueueSession = JmsTracing.create(messagingTracing).queueConnection(jms.queueConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        messageConsumer = tracedQueueSession.createConsumer(jms.queue);
        queueSender.send(message);
        // Check that the message headers are not sampled
        assertThat(messageConsumer.receive().getStringProperty("b3")).endsWith("-0");
    }
// @After will also check that the consumer was not sampled
}
Also used : MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) Test(org.junit.Test)

Example 2 with MessagingRuleSampler

use of brave.messaging.MessagingRuleSampler 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
}
Also used : JMSConsumer(javax.jms.JMSConsumer) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Example 3 with MessagingRuleSampler

use of brave.messaging.MessagingRuleSampler in project brave by openzipkin.

the class ITJms_1_1_TracingMessageProducer method customSampler.

@Test
public void customSampler() throws JMSException {
    queueSender.close();
    tracedQueueSession.close();
    MessagingRuleSampler producerSampler = MessagingRuleSampler.newBuilder().putRule(channelNameEquals(jms.queue.getQueueName()), Sampler.NEVER_SAMPLE).build();
    try (MessagingTracing messagingTracing = MessagingTracing.newBuilder(tracing).producerSampler(producerSampler).build()) {
        // JMS 1.1 didn't have auto-closeable. tearDownTraced closes these
        tracedQueueSession = JmsTracing.create(messagingTracing).queueConnection(jms.queueConnection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        queueSender = tracedQueueSession.createSender(jms.queue);
        queueSender.send(message);
    }
    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
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) BytesMessage(javax.jms.BytesMessage) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) Test(org.junit.Test)

Example 4 with MessagingRuleSampler

use of brave.messaging.MessagingRuleSampler 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
}
Also used : Message(javax.jms.Message) MessagingTracing(brave.messaging.MessagingTracing) MessagingRuleSampler(brave.messaging.MessagingRuleSampler) JMSContext(javax.jms.JMSContext) Test(org.junit.Test)

Aggregations

MessagingRuleSampler (brave.messaging.MessagingRuleSampler)4 MessagingTracing (brave.messaging.MessagingTracing)4 Test (org.junit.Test)4 JMSContext (javax.jms.JMSContext)2 Message (javax.jms.Message)2 BytesMessage (javax.jms.BytesMessage)1 JMSConsumer (javax.jms.JMSConsumer)1 TextMessage (javax.jms.TextMessage)1