<commit_before>> This document contains documentation for the tracee-jms module. Click [here](/README.md) to get an overview that TracEE is about.

# tracee-jms

> This module can be used to add TracEE context propagation support to JMS MessageProducer and MessageListener beans.


Please add the following dependencies to enable TracEE's JMS support. For example in maven-style projects add to the pom.xml:

```xml
<dependencies>
    ...
    <dependency>
        <groupId>io.tracee</groupId>
        <artifactId>tracee-jms</artifactId>
        <version>RELEASE</version>
    </dependency>
    ...
</dependencies>
```

## Using MessageProducer
You can use the TracEE context propagation for JMS by wrapping the MessageProducer with TraceeMessageWriter.wrap(messageProdecer).

```java
import io.tracee.jms.TraceeMessageWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.*;

@Stateless
public class MessageProducerImpl implements MessageProducer {

	@Resource(mappedName = "java:/ConnectionFactory")
	private ConnectionFactory connectionFactory;

	@Resource(mappedName = "java:/exampleQueue")
	private Queue exampleQueue;

	@Resource(mappedName = "java:/exampleTopic")
	private Topic exampleTopic;

	@Override
	public void sendToQueue(String message) {
		sendToDestination(message, exampleQueue);
	}

	@Override
	public void sendToTopic(String message) {
		sendToDestination(message, exampleTopic);
	}

	private void sendToDestination(String message, Destination destination) {
	  Connection connection = null;
		try {
			connection = connectionFactory.createConnection();
	    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	    
		  // wrap the producer to enable TracEE
		  final javax.jms.MessageProducer producer = TraceeMessageWriter.wrap(session.createProducer(destination));
		  
		  final TextMessage textMessage = session.createTextMessage();
		  textMessage.setText(message);
		  producer.send(textMessage);
		} catch (JMSException jmse) {
			// handle exception ...
		}
	}
	
}

```

## Using MessageListerner
You only have to add the TraceeMessageListener interceptor to your MesssageDriven bean:

```java
import io.tracee.jms.TraceeMessageListener;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.interceptor.Interceptors;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(
				propertyName = "destination", propertyValue = "exampleQueue")})
@Interceptors({TraceeMessageListener.class})
public class MessageQueueListener implements MessageListener {

	@Override
	public void onMessage(Message message) {
		// .. 
	}

}
```

## Background
To enable TracEE's context information in JMS, the MessageProducer must add TracEE's contextual information to the message before it gets persisted. Therefore TracEE offers the TraceeMessageWriter that wraps the MessageProducer and provides those informations before they will be scheduled to a queue or topic.

Thee MessageListeners need to extract those contextual information before the Message is going to be processed.
This can be done easily done by using the TraceeMessageListener interceptor.<commit_msg>Update Readme.md [skip ci]<commit_after>> This document contains documentation for the tracee-jms module. Click [here](/README.md) to get an overview that TracEE is about.

# tracee-jms

> This module can be used to add TracEE context propagation support to JMS MessageProducer and MessageListener beans.


Please add the following dependencies to enable TracEE's JMS support. For example in maven-style projects add to the pom.xml:

```xml
<dependencies>
    ...
    <dependency>
        <groupId>io.tracee</groupId>
        <artifactId>tracee-jms</artifactId>
        <version>RELEASE</version>
    </dependency>
    ...
</dependencies>
```

## Using MessageProducer
You can use the TracEE context propagation for JMS by wrapping the MessageProducer with TraceeMessageWriter.wrap(messageProdecer).

```java
import io.tracee.jms.TraceeMessageWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.jms.*;

@Stateless
public class MessageProducerImpl implements MessageProducer {

	@Resource(mappedName = "java:/ConnectionFactory")
	private ConnectionFactory connectionFactory;

	@Resource(mappedName = "java:/exampleQueue")
	private Queue exampleQueue;

	@Resource(mappedName = "java:/exampleTopic")
	private Topic exampleTopic;

	@Override
	public void sendToQueue(String message) {
		sendToDestination(message, exampleQueue);
	}

	@Override
	public void sendToTopic(String message) {
		sendToDestination(message, exampleTopic);
	}

	private void sendToDestination(String message, Destination destination) {
	  Connection connection = null;
		try {
			connection = connectionFactory.createConnection();
	    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	    
		  // wrap the producer to enable TracEE
		  final javax.jms.MessageProducer producer = TraceeMessageWriter.wrap(session.createProducer(destination));
		  
		  final TextMessage textMessage = session.createTextMessage();
		  textMessage.setText(message);
		  producer.send(textMessage);
		} catch (JMSException jmse) {
			// handle exception ...
		}
	}
	
}

```

## Using MessageListerner
You only have to add the TraceeMessageListener interceptor to your MesssageDriven bean:

```java
import io.tracee.jms.TraceeMessageListener;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.interceptor.Interceptors;
import javax.jms.Message;
import javax.jms.MessageListener;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(
				propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(
				propertyName = "destination", propertyValue = "exampleQueue")})
@Interceptors({TraceeMessageListener.class})
public class MessageQueueListener implements MessageListener {

	@Override
	public void onMessage(Message message) {
		// .. 
	}

}
```

## Background
To enable TracEE's context information in JMS, the MessageProducer must add TracEE's contextual information to the message before it gets persisted. Therefore TracEE offers the TraceeMessageWriter that wraps the MessageProducer.
It adds the contextual informations to the Message before the Message is going to be persisted and scheduled to a queue or topic.

Thee MessageListeners need to extract those contextual information before the Message is going to be processed.
This can be done easily done by using the TraceeMessageListener interceptor.
{'fraction_non_alphanumeric': 0.08167417526522308, 'fraction_numerical': 0.0005813108559802354, 'mean_word_length': 4.989556135770235, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5792003', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1863, 'n_words': 587}