/** * Convenience for {@link #jmsTopicBuilder(DistributedSupplier)}. Creates a * connection without any authentication parameters and uses non-transacted * sessions with {@code Session.AUTO_ACKNOWLEDGE} mode. If a received item * is not an instance of {@code javax.jms.Message}, the sink wraps {@code * item.toString()} into a {@link javax.jms.TextMessage}. * * @param factorySupplier supplier to obtain JMS connection factory * @param name the name of the queue */ @Nonnull public static <T> Sink<T> jmsTopic( @Nonnull DistributedSupplier<ConnectionFactory> factorySupplier, @Nonnull String name ) { return Sinks.<T>jmsTopicBuilder(factorySupplier) .destinationName(name) .build(); }
/** * Returns a builder object that offers a step-by-step fluent API to build * a custom JMS topic sink for the Pipeline API. See javadoc on {@link * JmsSinkBuilder} methods for more details. * <p> * Behavior on job restart: the processor is stateless. If the job is * restarted, duplicate events can occur. If you need exactly-once behavior, * you must ensure idempotence on the application level. * <p> * IO failures should be handled by the JMS provider. If any JMS operation * throws an exception, the job will fail. Most of the providers offer a * configuration parameter to enable auto-reconnection, refer to provider * documentation for details. * <p> * Default local parallelism for this processor is 4 (or less if less CPUs * are available). * * @param <T> type of the items the sink accepts */ @Nonnull public static <T> JmsSinkBuilder<T> jmsTopicBuilder(@Nonnull DistributedSupplier<ConnectionFactory> factorySupplier) { return new JmsSinkBuilder<>(factorySupplier, true); }
private static Pipeline buildPipeline() { Pipeline p = Pipeline.create(); p.drawFrom(Sources.jmsTopic(() -> new ActiveMQConnectionFactory(ActiveMQBroker.BROKER_URL), INPUT_TOPIC)) .filter(message -> message.getJMSPriority() > 3) .map(message -> (TextMessage) message) // print the message text to the log .peek(TextMessage::getText) .drainTo(Sinks.<TextMessage>jmsTopicBuilder(() -> new ActiveMQConnectionFactory(ActiveMQBroker.BROKER_URL)) .destinationName(OUTPUT_TOPIC) .messageFn((session, message) -> { TextMessage textMessage = session.createTextMessage(message.getText()); textMessage.setBooleanProperty("isActive", true); textMessage.setJMSPriority(8); return textMessage; }) .build()); return p; }
DistributedSupplier<ConnectionFactory> factorySupplierLocal = factorySupplier; DistributedSupplier<Connection> connectionSupplier = () -> connectionFnLocal.apply(factorySupplierLocal.get()); return new SinkImpl<>(sinkName(), WriteJmsP.supplier(connectionSupplier, sessionFn, messageFn, sendFn, flushFn, destinationName, isTopic));
private static Pipeline buildPipeline() { Pipeline p = Pipeline.create(); p.drawFrom(Sources.jmsQueue(() -> new ActiveMQConnectionFactory(ActiveMQBroker.BROKER_URL), INPUT_QUEUE)) .filter(message -> message.getJMSPriority() > 3) .map(message -> (TextMessage) message) // print the message text to the log .peek(TextMessage::getText) .drainTo(Sinks.<TextMessage>jmsQueueBuilder(() -> new ActiveMQConnectionFactory(ActiveMQBroker.BROKER_URL)) .destinationName(OUTPUT_QUEUE) .messageFn((session, message) -> { // create new text message with the same text and few additional properties TextMessage textMessage = session.createTextMessage(message.getText()); textMessage.setBooleanProperty("isActive", true); textMessage.setJMSPriority(8); return textMessage; } ) .build()); return p; }
/** * Convenience for {@link #jmsQueueBuilder(DistributedSupplier)}. Creates a * connection without any authentication parameters and uses non-transacted * sessions with {@code Session.AUTO_ACKNOWLEDGE} mode. If a received item * is not an instance of {@code javax.jms.Message}, the sink wraps {@code * item.toString()} into a {@link javax.jms.TextMessage}. * * @param factorySupplier supplier to obtain JMS connection factory * @param name the name of the queue */ @Nonnull public static <T> Sink<T> jmsQueue( @Nonnull DistributedSupplier<ConnectionFactory> factorySupplier, @Nonnull String name ) { return Sinks.<T>jmsQueueBuilder(factorySupplier) .destinationName(name) .build(); }
/** * Returns a builder object that offers a step-by-step fluent API to build * a custom JMS queue sink for the Pipeline API. See javadoc on {@link * JmsSinkBuilder} methods for more details. * <p> * Behavior on job restart: the processor is stateless. If the job is * restarted, duplicate events can occur. If you need exactly-once behavior, * you must ensure idempotence on the application level. * <p> * IO failures should be handled by the JMS provider. If any JMS operation * throws an exception, the job will fail. Most of the providers offer a * configuration parameter to enable auto-reconnection, refer to provider * documentation for details. * <p> * Default local parallelism for this processor is 4 (or less if less CPUs * are available). * * @param <T> type of the items the sink accepts */ @Nonnull public static <T> JmsSinkBuilder<T> jmsQueueBuilder(@Nonnull DistributedSupplier<ConnectionFactory> factorySupplier) { return new JmsSinkBuilder<>(factorySupplier, false); }