To use the amqp component inside Karaf use the predefined feature called camel-amqp to install the necessary bundles. If you consume a message on a queue, you should see the following files under the data/activemq folder :Ĭontaining the following string: Getting Component JARĪctiveMQ is an extension of the JMS component released with the ActiveMQ project. Next, the body received is converted into a String for the purposes of this example and a carriage return is added. The parameter mapJmsMessage=false allows for converting the .ActiveMqMessage object from the JMS queue. To watch another topic, simply change the name according to the name provided in ActiveMQ Advisory Messages documentation. The below route starts by reading the topic. Such messages can help you send alerts in case you detect slow consumers or to build statistics (number of messages/produced per day, etc.) The following Spring DSL example shows you how to read messages from a topic. For example to mark a consumer as exclusive, and set its prefetch size to 50, you can do as follows:ĪctiveMQ can generate Advisory messages which are put in topics that you can consume. You can configure the Destination Options in the endpoint URI, using the destination. That is, you can reuse any of the Camel Components and easily integrate them into your JMS MessageListener POJO! Using ActiveMQ Destination Options Then use it in your Camel route as follows So for example you can create a MessageListener in JMS like this: This means that the Bean component is capable of invoking any JMS MessageListener bean directly inside any route. The ActiveMQ component also provides a helper Type Converter from a JMS MessageListener to a Processor. Invoking MessageListener POJOs in a Camel route In this example we can have 8 * 500 = 4000 active sessions at the same time. This is okay, as each consumer is using a session, and as a session can share the same connection, we are in the safe. Notice the concurrentConsumers is set to a higher value than maxConnections is. From ActiveMQ 5.7: the option has been renamed to better reflect its purpose, being named as maximumActiveSessionPerConnection. There is an option named maximumActive you can use to configure the maximum number of sessions per connection the default value is 500. Each connection can be shared by many sessions. The PooledConnectionFactory will then create a connection pool with up to 8 connections in use at the same time. This can dramatically improve performance. And remember to set cacheLevelName to CACHE_CONSUMER if you are not using XA transactions. If you are using transactions then see more details at JMS. Important information about when using transactions This is important to ensure the connection pool is properly started and shutdown. Notice the init and destroy methods on the pooled connection factory. You can grab ActiveMQ's .PooledConnectionFactory with Maven: xml activemq-pool 5.6.0Īnd then setup the activemq Camel component as follows: xml This is documented on the ActiveMQ Spring Support page. When sending to an ActiveMQ broker using Camel it's recommended to use a pooled connection factory to efficiently handle pooling of JMS connections, sessions and producers. You can configure the ActiveMQ broker URL on the ActiveMQComponent as follows xml Configuring the Connection Factory using Spring XML This test case shows how to add an ActiveMQComponent to the CamelContext using the activeMQComponent() method while specifying the brokerURL used to connect to ActiveMQ. See Options on the JMS component as all these options also apply for this component. For example, to connect to the topic, Stocks.Prices, use: Options To connect to a topic, you must include the topic: prefix. You can include the optional queue: prefix, if you prefer: For example, to connect to the queue, FOO.BAR, use: By default, the destinationName is interpreted as a queue name. Where destinationName is an ActiveMQ queue or topic name. See section Transactions and Cache Levels below on JMS page if you are using transactions with JMS as it can impact performance. To use this component make sure you have the activemq.jar or activemq-core.jar on your classpath along with any Camel dependencies such as camel-core.jar, camel-spring.jar and camel-jms.jar. All the options from the JMS component also applies for this component. This component is based on JMS Component and uses Spring's JMS support for declarative transactions, using Spring's JmsTemplate for sending and a MessageListenerContainer for consuming. The ActiveMQ component allows messages to be sent to a JMS Queue or Topic or messages to be consumed from a JMS Queue or Topic using Apache ActiveMQ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |