blob: 4884c9f953577a6ca68025d7c2ba77feb870b9c0 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>ActiveMQ</title>
<link rel="icon" type="image/png" href="/assets/img/favicon.png">
<link rel="stylesheet" href="/css/main.css">
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js" integrity="sha384-SlE991lGASHoBfWbelyBPLsUlwY1GwNDJo3jSJO04KZ33K2bwfV9YBauFfnzvynJ" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
<div class="container">
<!-- <a class="navbar-brand mr-auto" href="#"><img style="height: 50px" src="assets/img/apache-feather.png" /></a> -->
<a class="navbar-brand mr-auto" href="/"><img src="/assets/img/activemq_logo_black_small.png" style="height: 50px"/></a>
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="ml-auto collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a class="nav-link active" href="/index.html">Home</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownComponents" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Components</a>
<ul class="dropdown-menu dropdown-menu-center" aria-labelledby="navbarDropdownComponents">
<div class="row">
<div class="col-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="/components/classic">ActiveMQ 5</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/artemis/">ActiveMQ Artemis</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/nms">NMS Clients</a></li>
<li class="nav-item"><a class="dropdown-item" href="/components/cms">CMS Client</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownCommunity" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Contact</a>
<ul class="dropdown-menu dropdown-menu-center multi-column columns-1" aria-labelledby="navbarDropdownCommunity">
<div class="row">
<div class="col-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="/contact#mailing">Mailing Lists</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#chat">Chat</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#issues">Report Issues</a></li>
<li class="nav-item"><a class="dropdown-item" href="/contact#contributing">Contributing</a></li>
<li class="nav-item"><a class="dropdown-item" href="/security-advisories.html">Security</a></li>
</ul>
</div>
</div>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link" id="navbarDropdownTeam" data-target="#" href="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Apache</a>
<ul class="dropdown-menu dropdown-menu-center multi-column columns-1" aria-labelledby="navbarDropdownTeam">
<div class="row">
<div class="col-sm-12">
<ul class="multi-column-dropdown">
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org">The Apache Software Foundation</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/licenses/">License</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li class="nav-item"><a class="dropdown-item" href="/security-advisories.html">Security</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://www.apache.org/events/current-event">Events</a></li>
<li class="nav-item"><a class="dropdown-item" href="https://people.apache.org/phonebook.html?pmc=activemq">PMC & Committers</a></li>
<li class="nav-item"><a class="dropdown-item" href="/team/reports">Board Reports</a></li>
</ul>
</div>
</div>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="content">
<div class="page-title-activemq5">
<div class="container">
<h1>Broker Camel Component</h1>
</div>
</div>
<div class="container" >
<div class="row" style="margin-top: 30px">
<div class="col-12 activemq5">
<p><a href="features">Features</a> &gt; <a href="broker-camel-component">Broker Camel Component</a></p>
<h2 id="broker-camel-component">Broker Camel Component</h2>
<p><strong>Available as of ActiveMQ 5.9</strong></p>
<p>Embedding Apache Camel inside the ActiveMQ broker provides great flexibility for extending the message broker with the integration power of Camel. Apache Camel routes also benefit in that you can avoid the serialization and network costs of connecting to ActiveMQ remotely - if you use the <a href="http://camel.apache.org/activemq.html">activemq component</a>.</p>
<p>If however, you want to change the behavior of messages flowing through the ActiveMQ message broker itself you will be limited to the shipped set of ActiveMQ broker <a href="interceptors">Interceptors</a> - or develop your own <a href="developing-plugins">Broker plugin</a> and then introduce that as a jar on to the class path for the ActiveMQ broker. The <code class="highlighter-rouge">broker</code> Camel component makes this even easier. It intercepts messages as they move through the broker itself, allowing them to be modified and manipulated before they are persisted to the message store or delivered to end consumers.</p>
<p>For example <a href="how-should-i-package-applications-using-camel-and-activemq">by defining a CamelContext to run inside the broker’s JVM</a> the <code class="highlighter-rouge">broker</code> component can intercept all messages published to a Topic, say, and publish them to a Queue instead, changing their priority along the way:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;route id="setPriority"&gt;
&lt;from uri="broker:topic:test.broker.&gt;"/&gt;
&lt;setHeader headerName="JMSPriority"&gt;
&lt;constant&gt;9&lt;/constant&gt;
&lt;/setHeader&gt;
&lt;to uri="broker:queue:test.broker.component.queue"/&gt;
&lt;/route&gt;
</code></pre></div></div>
<p>Notes:</p>
<ul>
<li>A broker component only adds an intercept into the broker if its started - so the broker component will not add any overhead to the running broker until its used - and then the overhead will be trivial.</li>
<li>Messages are intercepted by the broker component when they have been received by the broker - but before they are processed (persisted or routed to a destination).</li>
<li>The <code class="highlighter-rouge">IN</code> message on the Exchange is a <code class="highlighter-rouge">CamelMessage</code>, but also a JMS Message (messages routed through ActiveMQ from STOMP/MQTT/AMQP etc. are always translated into JMS messages).</li>
<li><a href="wildcards">Wildcards</a> can be used on a destination to intercept messages from destinations matching the wildcard.</li>
<li>After the intercept, you have to explicitly send the message back to the broker component - this allows you to either drop select messages (by not sending) - or, like in the above case - re-route the message to a different destination.</li>
</ul>
<p>There is one deliberate caveat though, only intercepted messages can be sent to a <code class="highlighter-rouge">broker</code> component. For example, routing a Camel message from another Component e.g. <code class="highlighter-rouge">file</code>, will result in an error.</p>
<p>Extra classes that have been added to the <code class="highlighter-rouge">activemq-broker</code> package to support the <code class="highlighter-rouge">broker</code> component. They allow the state of the running broker to be interrogated without using JMX. These classes are:</p>
<ul>
<li><a href="http://activemq.apache.org/maven/5.9.0/apidocs/org/apache/activemq/broker/view/MessageBrokerView.html">org.apache.activemq.broker.view.MessageBrokerView</a> - provides methods to retrieve statistics on a the broker</li>
<li>From the <code class="highlighter-rouge">org.apache.activemq.broker.view.MessageBrokerView</code> - you can retrieve a <a href="http://activemq.apache.org/maven/5.9.0/apidocs/org/apache/activemq/broker/view/BrokerDestinationView.html">org.apache.activemq.broker.view.BrokerDestinationView</a> for a particular destination.</li>
</ul>
<h3 id="example">Example</h3>
<p>How to route messages when a destination’s queue depth has reached a certain limit:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>&lt;camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring"&gt;
&lt;route id="routeAboveQueueLimitTest"&gt;
&lt;from uri="broker:queue:test.broker.queue"/&gt;
&lt;choice&gt;
&lt;when&gt;
&lt;spel&gt;#{@destinationView.queueSize &gt;= 100}&lt;/spel&gt;
&lt;to uri="broker:queue:test.broker.processLater"/&gt;
&lt;/when&gt;
&lt;otherwise&gt;
&lt;to uri="broker:queue:test.broker.queue"/&gt;
&lt;/otherwise&gt;
&lt;/choice&gt;
&lt;/route&gt;
&lt;/camelContext&gt;
&lt;bean id="brokerView" class="org.apache.activemq.broker.view.MessageBrokerView"&gt;
&lt;constructor-arg value="testBroker"/&gt;
&lt;/bean&gt;
&lt;bean id="destinationView" factory-bean="brokerView" factory-method="getDestinationView"&gt;
&lt;constructor-arg value="test.broker.component.route"/&gt;
&lt;/bean&gt;
</code></pre></div></div>
<p>This is using the Camel Message Router pattern. Note the use of the Spring expression language <code class="highlighter-rouge">spel</code> in the <code class="highlighter-rouge">when</code> clause.</p>
</div>
</div>
</div>
</div>
<div class="row sitemap">
<div class="col-sm-12">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-3">
<div >
<img class="float-left" style="max-height: 100px" src="/assets/img/activemq_logo_white_vertical_small.png"/>
</div>
</div>
<div style="text-align: center; margin-bottom: 0px; margin-top: 30px; font-size: 65%" class="col-sm-6">
<p>Apache ActiveMQ, ActiveMQ, ActiveMQ Artemis, Apache, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. Copyright &copy; 2019, The Apache Software Foundation. Licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>.</p>
</div>
<div class="col-sm-3">
<div >
<a href="https://www.apache.org"><img class="float-right" style="margin-top: 10px; max-height: 80px" src="/assets/img/apache-logo-small.png"/></a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>