Search in sources :

Example 1 with BundleSender

use of io.openk9.ingestion.api.BundleSender in project openk9 by smclab.

the class StartEnrichProcessorImpl method exec.

@Override
public Mono<Void> exec(ObjectNode objectNode) {
    return Mono.defer(() -> {
        ArrayNode originalDependencies = objectNode.get("dependencies").toArrayNode();
        if (originalDependencies.isEmpty()) {
            return _endEnrichProcessor.exec(objectNode);
        }
        String routingKey = originalDependencies.remove(0).asText();
        BundleSender bundleSender = _bundleSenderProvider.getBundleSender(routingKey);
        return bundleSender.send(Mono.just(objectNode.toString().getBytes()));
    });
}
Also used : BundleSender(io.openk9.ingestion.api.BundleSender) ArrayNode(io.openk9.json.api.ArrayNode)

Example 2 with BundleSender

use of io.openk9.ingestion.api.BundleSender 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;
}
Also used : ArrayList(java.util.ArrayList) AMQP(com.rabbitmq.client.AMQP) BindingSpecification(reactor.rabbitmq.BindingSpecification) Binding(io.openk9.ingestion.api.Binding) BundleSender(io.openk9.ingestion.api.BundleSender) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) BundleReceiver(io.openk9.ingestion.api.BundleReceiver)

Aggregations

BundleSender (io.openk9.ingestion.api.BundleSender)2 AMQP (com.rabbitmq.client.AMQP)1 Binding (io.openk9.ingestion.api.Binding)1 BundleReceiver (io.openk9.ingestion.api.BundleReceiver)1 ArrayNode (io.openk9.json.api.ArrayNode)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Bundle (org.osgi.framework.Bundle)1 BindingSpecification (reactor.rabbitmq.BindingSpecification)1