Tutorials on Apache Camel, Apache Kafka, JBoss Fuse

Search our tutorials

Selector are Properties which are set in the Header of the JMS Message so that you can filter only the messages which are compliant with the filter. You can set the selector using the selector attribute which is an SQL 92 predicate that is used to filter messages within the broker. You may have to encode special characters like '=' as %3D.

Here is an example of two routes:

import java.io.IOException;

import javax.jms.ConnectionFactory;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;

public class App {
	public static void main(String args[]) throws Exception {
		CamelContext context = new DefaultCamelContext();
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
		context.addRoutes(new RouteBuilder() {
			public void configure() {
				from("timer:foo?period=1s").setBody(simple("Message at ${date:now:yyyy-MM-dd HH:mm:ss}")).to(
				from("activemq:queue:somequeue?selector=clientid %3D 'someid'").to("activemq:queue:otherqueue"); 
		try {
	    } catch (IOException e) {

Only messages which contain the header "clientid = 'someid'" are allowed to transit from "somequeue" to "otherqueue".

FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials