Support planned for Fall 2014

Icon

Out-of-the-Box Support for RabbitMQ is planned for the 2014 Fall Release (link to the forum post).

  

In the meantime, the Tagging ADK for Java/.Net can be utilized to get full end-to-end visibility. 

Sample for RabbitMQ Tagging

Below is an example on instrumenting a simple RabbitMQ HelloWorld example.

RabbitMQ Sender

The Sender of the RabbitMQ looks like this:

package com.compuware.fts.rabbitmq;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import com.dynatrace.adk.DynaTraceADKFactory;
import com.dynatrace.adk.Tagging;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;

public class Sender {

static Tagging myTaggingSDK;

static {
   // Initialize the ADK.
   DynaTraceADKFactory.initialize();
   myTaggingSDK = DynaTraceADKFactory.createTagging();
} 

private final static String QUEUE_NAME = "hello";

public static void main(String[] argv) throws Exception {
   sendMessage();
   Thread.sleep(10000);
}

public static void sendMessage() throws Exception {
   ConnectionFactory factory = new ConnectionFactory();

   //The host running RabbitMQ
   factory.setHost("192.168.1.13");
   Connection connection = factory.newConnection();
   Channel channel = connection.createChannel();

 

   channel.queueDeclare(QUEUE_NAME, false, false, false, null);
   String message = "Hello World!";

   // Get the current Tag and add it to the dtdTraceTagInfo message header
   String tag = myTaggingSDK.getTagAsString();
   myTaggingSDK.linkClientPurePath(true);
   Map<String, Object> headers = new HashMap();
   headers.put("dtdTraceTagInfo", tag);

   BasicProperties props = new BasicProperties().builder().headers(headers).build(); 

   for (int i = 0; i < 1000; i++) {

      channel.basicPublish("", QUEUE_NAME, props, message.getBytes());
      System.out.println(" [x] Sent '" + message + "'");
      Thread.sleep(100);
   }

   channel.close();
   connection.close();
}

}

RabbitMQ Receiver

The receiver of the RabbitMQ message would need to get tagged like below: 

package com.compuware.fts.rabbitmq;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.dynatrace.adk.DynaTraceADKFactory;
import com.dynatrace.adk.Tagging;
import com.rabbitmq.client.AMQP.BasicProperties;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.QueueingConsumer.Delivery;

public class Receiver {

private final static String QUEUE_NAME = "hello";

static Tagging myTaggingSDK;

static {
   // Initialize the ADK
   DynaTraceADKFactory.initialize();
   myTaggingSDK = DynaTraceADKFactory.createTagging();
}

public static void main(String[] argv) throws Exception {
   handleMessages();
}

public static void handleMessages() throws Exception, InterruptedException {
   ConnectionFactory factory = new ConnectionFactory();
   // The host running RabbitMQ
   factory.setHost("192.168.1.13");
   Connection connection = factory.newConnection();
   Channel channel = connection.createChannel();

   channel.queueDeclare(QUEUE_NAME, false, false, false, null);
   System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

   QueueingConsumer consumer = new QueueingConsumer(channel);
   channel.basicConsume(QUEUE_NAME, true, consumer);

   while (true) {
      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
      connectPurePath(delivery);
      processMessage(delivery);
      endPurePath();
   }
}

/**
* The work to for processing a message. This example simply iterates through the message headers and prints them out.
* @param delivery The Message to Process.
* @throws Exception
*/
public static void processMessage(Delivery delivery) throws Exception {
   String message = new String(delivery.getBody());
   System.out.println(" [x] Received '" + message + "'");
   BasicProperties props = delivery.getProperties();
   if (props != null) {
      Map<String, Object> header = props.getHeaders();
      if (header != null) {
         Set<Entry<String, Object>> headers = header.entrySet();
         for (Entry<String, Object> entry : headers) {
            System.out.println("--Header: " + entry.getKey() + " Value: " + entry.getValue());
         }
      }
   }

   // Simulate some additional work.
   Thread.sleep(1000);
   }

/**
* Extracts dtdTraceTagInfo from the message and makes the ADK calls to connect the PurePath.
*
* @param delivery The message containing the dynaTrace tag in the dtdTraceTagInfo header
*/
public static void connectPurePath(QueueingConsumer.Delivery delivery) {
   BasicProperties props1 = delivery.getProperties();
   if (props1 != null) {
      Map<String, Object> header1 = props1.getHeaders();
      if (header1 != null) {
         Set<Entry<String, Object>> headers = header1.entrySet();
         for (Entry<String, Object> entry : headers) {
            if ("dtdTraceTagInfo".equals(entry.getKey())) {
               String tag = entry.getValue().toString();
               myTaggingSDK.setTagFromString(tag);
               myTaggingSDK.startServerPurePath();
             }
          }
       }
   }
}

/**
* Ends the current PurePath for this node.
*/
public static void endPurePath() {
myTaggingSDK.endServerPurePath();
} 

}




  • No labels
  1. Anonymous (login to see details)

    Hi Andreas,

    is there an out-of-the-box support already for Rabbit MQ (in PHP environment)?

    (sorry if yes, but i could not find it!)

    cheers,

    Peter Bogdanov

    1. Anonymous (login to see details)

      Hi Peter

      Not for PHP as far as I know. But - thats an interesting request that you could put as an RFE into our RFE Forum!