use of io.openk9.ingestion.api.Binding in project openk9 by smclab.
the class EnrichProcessorServiceTracker method addingService.
@Override
public EnrichProcessor addingService(ServiceReference<EnrichProcessor> reference) {
List<AutoCloseable> autoCloseableSafes = new ArrayList<>();
EnrichProcessor service = _bundleContext.getService(reference);
Binding binding = Binding.of(exchange, service.name(), service.name());
ServiceRegistration<Binding> serviceRegistration = _bundleContext.registerService(Binding.class, binding, new Hashtable<>());
autoCloseableSafes.add(serviceRegistration::unregister);
if (service instanceof AsyncEnrichProcessor) {
AsyncEnrichProcessor asyncEnrichProcessor = ((AsyncEnrichProcessor) service);
Binding bindingDestinationName = Binding.of(exchange, asyncEnrichProcessor.destinationName(), asyncEnrichProcessor.destinationName());
ServiceRegistration<Binding> destinationNameServiceRegistration = _bundleContext.registerService(Binding.class, bindingDestinationName, new Hashtable<>());
autoCloseableSafes.add(destinationNameServiceRegistration::unregister);
}
EnrichProcessorExtension enrichProcessorExtension = new EnrichProcessorExtension(reference.getBundle(), service, prefetch);
enrichProcessorExtension.start();
autoCloseableSafes.add(enrichProcessorExtension::destroy);
_map.put(service, AutoCloseables.mergeAutoCloseableToSafe(autoCloseableSafes));
return service;
}
use of io.openk9.ingestion.api.Binding in project openk9 by smclab.
the class BindingServiceTrackerCustomizer method addingService.
@Override
public Binding addingService(ServiceReference<Binding> reference) {
Binding service = _bundleContext.getService(reference);
Bundle bundle = reference.getBundle();
Binding.Exchange exchangeDTO = service.getExchange();
String exchange = exchangeDTO.getName();
String routingKey = service.getRoutingKey();
String queue = service.getQueue();
Binding.Exchange.Type exchangeType = exchangeDTO.getType();
Mono<AMQP.Exchange.DeclareOk> mono1 = _sender.declareExchange(ExchangeSpecification.exchange(exchange).type(exchangeType.name()).durable(exchange.startsWith("amq") || service.exchangeDurable()));
List<AutoCloseable> autoCloseables = new ArrayList<>();
if (queue != null) {
Mono<AMQP.Queue.DeclareOk> mono2 = _sender.declareQueue(QueueSpecification.queue(queue).durable(service.queueDurable()).arguments(service.getArguments()));
BindingSpecification binding = BindingSpecification.binding(exchange, routingKey, queue);
autoCloseables.add(() -> _sender.unbind(binding).subscribe());
Mono<AMQP.Queue.BindOk> mono3 = _sender.bind(binding);
if (Schedulers.isInNonBlockingThread()) {
Mono.zip(mono1, mono2, mono3).subscribe();
} else {
Mono.zip(mono1, mono2, mono3).block();
}
} else {
if (Schedulers.isInNonBlockingThread()) {
mono1.subscribe();
} else {
mono1.block();
}
}
_log.info(String.format("Bundle: %s, Service: %s, exchange: %s, exchange type: %s, " + "routingKey: %s, queue: %s", bundle.getSymbolicName(), service.getClass().getName(), exchange, exchangeType.name(), routingKey, queue));
Dictionary<String, Object> senderProps = new Hashtable<>();
senderProps.put("exchange", exchange);
if (routingKey != null) {
senderProps.put("routingKey", routingKey);
}
if (queue != null) {
senderProps.put("queue", queue);
}
senderProps.put("exchangeType", exchangeType.name());
ServiceRegistration<BundleSender> bundleSenderRegistration = bundle.getBundleContext().registerService(BundleSender.class, new BundleSenderImpl(_sender, exchange, routingKey), senderProps);
autoCloseables.add(bundleSenderRegistration::unregister);
if (queue != null) {
ServiceRegistration<BundleReceiver> bundleReceiverRegistration = bundle.getBundleContext().registerService(BundleReceiver.class, new BundleReceiverImpl(_receiverReactor, queue), new Hashtable<>(Collections.singletonMap("queue", queue)));
autoCloseables.add(bundleReceiverRegistration::unregister);
}
_registrationMap.put(bundle, AutoCloseables.mergeAutoCloseableToSafe(autoCloseables));
return null;
}
Aggregations