27 Temmuz 2020 Pazartesi

Camel JMSComponent Sınıfı

Örnek
Şu satırı dahil ederiz
import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.Component;
import org.apache.camel.component.jms.JmsComponent;
Örnek - Header Alanına Göre Yönlendirme
Şöyle yaparız
new DefaultCamelContext().addRoutes(new RouteBuilder() {
  public void configure() {
    from("jms:incomingMessages")
      .choice() // start router rules
        .when(header("CamelFileName")
          .endsWith(".xml"))
        .to("jms:xmlMessages")
        .when(header("CamelFileName")
          .endsWith(".csv"))
        .to("ftp:csvMessages");
}
Örnek - aggregate
Açıklaması şöyle
For starters, there are several implementations that are included out of the box. You can use them “as-is” without writing any custom code at all. Let’s talk through a few of them with some potential use cases.

The first is the org.apache.camel.processor.aggregate.UseLatestAggregationStrategy implementation. It’s the default strategy for most Camel EIPs that accept aggregation strategies. So if you don’t specify any strategy, this is likely the one you’re using. Basically, it takes the last exchange it receives and just uses that (ignoring any others that may have been aggregated prior). One example use case for this would be when doing an Aggregator. Perhaps you’re receiving many messages as input, but you want to buffer them (giving the user time to send in corrections/updates), and then only send the latest message to the backend after some period of inactivity.
Şöyle yaparız
from("jms:inbound")
.log("Received views change stream")
.bean(viewService, "updateDependencies")
.aggregate()
.header("JMSXGroupID")
.aggregationStrategy(new UseLatestAggregationStrategy())
.completionTimeout(600000) // 10 minutes
.completeAllOnStop()
.aggregationRepository(new LevelDBAggregationRepository("aggregation-repository",
  "./aggregation-repository"))
.log("Process views change stream")
.to("jms:outbound");
constructor
Şöyle yaparız
@Bean
public JmsComponent jms() throws JMSException {
  // Create the connectionfactory which will be used to connect to Artemis
  ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
  cf.setBrokerURL("tcp://localhost:61616");
  cf.setUser("artemis");
  cf.setPassword("artemis");

  //Create connection pool using connection factory
  PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
  pooledConnectionFactory.setMaxConnections(2);
  pooledConnectionFactory.setConnectionFactory(cf);

  //Create configuration which uses connection factory
  JmsConfiguration jmsConfiguration = new JmsConfiguration();
  jmsConfiguration.setConcurrentConsumers(2);
  jmsConfiguration.setArtemisStreamingEnabled(true);
  jmsConfiguration.setConnectionFactory(pooledConnectionFactory);

  // Create the Camel JMS component and wire it to our Artemis configuration
  JmsComponent jms = new JmsComponent();
  jms.setConfiguration(jmsConfiguration);
  return jms;
}
jmsComponentAutoAcknowledge metodu
Şöyle yaparız
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

Hiç yorum yok:

Yorum Gönder