use of org.apache.camel.impl.SimpleRegistry in project opennms by OpenNMS.
the class SyslogReceiverCamelNettyImpl method run.
/**
* The execution context.
*/
@Override
public void run() {
// Setup logging and create the dispatcher
super.run();
SimpleRegistry registry = new SimpleRegistry();
// Adding netty component to camel in order to resolve OSGi loading issues
NettyComponent nettyComponent = new NettyComponent();
m_camel = new DefaultCamelContext(registry);
// Set the context name so that it shows up nicely in JMX
//
// @see org.apache.camel.management.DefaultManagementNamingStrategy
//
// m_camel.setManagementName("org.opennms.features.events.syslog.listener");
m_camel.setName("syslogdListenerCamelNettyContext");
m_camel.setManagementNameStrategy(new DefaultManagementNameStrategy(m_camel, "#name#", null));
m_camel.addComponent("netty4", nettyComponent);
m_camel.getShutdownStrategy().setShutdownNowOnTimeout(true);
m_camel.getShutdownStrategy().setTimeout(15);
m_camel.getShutdownStrategy().setTimeUnit(TimeUnit.SECONDS);
try {
m_camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
String from = String.format("netty4:udp://%s:%d?sync=false&allowDefaultCodec=false&receiveBufferSize=%d&connectTimeout=%d", InetAddressUtils.str(m_host), m_port, Integer.MAX_VALUE, SOCKET_TIMEOUT);
from(from).routeId("syslogListen").process(new AsyncProcessor() {
@Override
public void process(Exchange exchange) throws Exception {
final ByteBuf buffer = exchange.getIn().getBody(ByteBuf.class);
// NettyConstants.NETTY_REMOTE_ADDRESS is a SocketAddress type but because
// we are listening on an InetAddress, it will always be of type InetAddressSocket
InetSocketAddress source = (InetSocketAddress) exchange.getIn().getHeader(NettyConstants.NETTY_REMOTE_ADDRESS);
// Synchronously invoke the dispatcher
m_dispatcher.send(new SyslogConnection(source, buffer.nioBuffer())).get();
}
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
final ByteBuf buffer = exchange.getIn().getBody(ByteBuf.class);
// NettyConstants.NETTY_REMOTE_ADDRESS is a SocketAddress type but because
// we are listening on an InetAddress, it will always be of type InetAddressSocket
InetSocketAddress source = (InetSocketAddress) exchange.getIn().getHeader(NettyConstants.NETTY_REMOTE_ADDRESS);
ByteBuffer bufferCopy = ByteBuffer.allocate(buffer.readableBytes());
buffer.getBytes(buffer.readerIndex(), bufferCopy);
m_dispatcher.send(new SyslogConnection(source, bufferCopy)).whenComplete((r, e) -> {
if (e != null) {
exchange.setException(e);
}
callback.done(false);
});
return false;
}
});
}
});
m_camel.start();
} catch (Throwable e) {
LOG.error("Could not configure Camel routes for syslog receiver", e);
}
}
use of org.apache.camel.impl.SimpleRegistry in project quickstarts by jboss-switchyard.
the class HL7Client method testSendA19.
public void testSendA19() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
HL7MLLPCodec codec = new HL7MLLPCodec();
codec.setCharset("iso-8859-1");
codec.setConvertLFtoCR(true);
registry.put("hl7codec", codec);
CamelContext camelContext = new DefaultCamelContext(registry);
camelContext.start();
ProducerTemplate template = camelContext.createProducerTemplate();
String line1 = "MSH|^~\\&|MYSENDER|MYRECEIVER|MYAPPLICATION||200612211200||QRY^A19|1234|P|2.4";
String line2 = "QRD|200612211200|R|I|GetPatient|||1^RD|0101701234|DEM||";
StringBuilder in = new StringBuilder();
in.append(line1);
in.append("\r");
in.append(line2);
template.requestBody("mina2:tcp://127.0.0.1:" + MINA2_PORT + "?sync=true&codec=#hl7codec", in.toString());
template.stop();
camelContext.stop();
}
use of org.apache.camel.impl.SimpleRegistry in project camel by apache.
the class XmlRpcEndpointTest method createRegistry.
protected Registry createRegistry() {
SimpleRegistry answer = new SimpleRegistry();
// Binding the client configurer
answer.put("myClientConfigurer", new MyClientConfigurer());
return answer;
}
use of org.apache.camel.impl.SimpleRegistry in project camel by apache.
the class HystrixHierarchicalConfigTest method testRegistryConfiguration.
@Test
public void testRegistryConfiguration() throws Exception {
final SimpleRegistry registry = new SimpleRegistry();
final CamelContext context = new DefaultCamelContext(registry);
HystrixConfigurationDefinition def = new HystrixConfigurationDefinition();
def.setGroupKey("global-group-key");
def.setThreadPoolKey("global-thread-key");
def.setCorePoolSize(10);
HystrixConfigurationDefinition ref = new HystrixConfigurationDefinition();
ref.setGroupKey("ref-group-key");
ref.setCorePoolSize(5);
registry.put(HystrixConstants.DEFAULT_HYSTRIX_CONFIGURATION_ID, def);
registry.put("ref-hystrix", ref);
final HystrixProcessorFactory factory = new HystrixProcessorFactory();
final HystrixConfigurationDefinition config = factory.buildHystrixConfiguration(context, new HystrixDefinition().hystrixConfiguration("ref-hystrix").hystrixConfiguration().groupKey("local-conf-group-key").requestLogEnabled(false).end());
Assert.assertEquals("local-conf-group-key", config.getGroupKey());
Assert.assertEquals("global-thread-key", config.getThreadPoolKey());
Assert.assertEquals(new Integer(5), config.getCorePoolSize());
}
use of org.apache.camel.impl.SimpleRegistry in project camel by apache.
the class HystrixHierarchicalConfigTest method testMixedConfiguration.
@Test
public void testMixedConfiguration() throws Exception {
final SimpleRegistry registry = new SimpleRegistry();
final CamelContext context = new DefaultCamelContext(registry);
HystrixConfigurationDefinition def = new HystrixConfigurationDefinition();
def.setGroupKey("global-group-key");
def.setThreadPoolKey("global-thread-key");
def.setCorePoolSize(10);
HystrixConfigurationDefinition ref = new HystrixConfigurationDefinition();
ref.setGroupKey("ref-group-key");
ref.setCorePoolSize(5);
// this should be ignored
HystrixConfigurationDefinition defReg = new HystrixConfigurationDefinition();
defReg.setGroupKey("global-reg-group-key");
defReg.setThreadPoolKey("global-reg-thread-key");
defReg.setCorePoolSize(20);
context.setHystrixConfiguration(def);
registry.put(HystrixConstants.DEFAULT_HYSTRIX_CONFIGURATION_ID, defReg);
registry.put("ref-hystrix", ref);
final HystrixProcessorFactory factory = new HystrixProcessorFactory();
final HystrixConfigurationDefinition config = factory.buildHystrixConfiguration(context, new HystrixDefinition().hystrixConfiguration("ref-hystrix").hystrixConfiguration().groupKey("local-conf-group-key").requestLogEnabled(false).end());
Assert.assertEquals("local-conf-group-key", config.getGroupKey());
Assert.assertEquals("global-thread-key", config.getThreadPoolKey());
Assert.assertEquals(new Integer(5), config.getCorePoolSize());
}
Aggregations