Class JmsIO.Write<EventT>
- All Implemented Interfaces:
Serializable
,JmsIO.ConnectionFactoryContainer<JmsIO.Write<EventT>>
,HasDisplayData
- Enclosing class:
JmsIO
PTransform
to write to a JMS queue. See JmsIO
for more information on usage
and configuration.- See Also:
-
Field Summary
Fields inherited from class org.apache.beam.sdk.transforms.PTransform
annotations, displayData, name, resourceHints
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexpand
(PCollection<EventT> input) Override this method to specify how thisPTransform
should be expanded on the givenInputT
.withConnectionFactory
(javax.jms.ConnectionFactory connectionFactory) Specify the JMS connection factory to connect to the JMS broker.withConnectionFactoryProviderFn
(SerializableFunction<Void, ? extends javax.jms.ConnectionFactory> connectionFactoryProviderFn) Specify a JMS connection factory provider function to connect to the JMS broker.withPassword
(String password) Define the password to connect to the JMS broker (authenticated).Specify the JMS queue destination name where to send messages to.withRetryConfiguration
(RetryConfiguration retryConfiguration) Specify the JMS retry configuration.Specify the JMS topic destination name where to send messages to.withTopicNameMapper
(SerializableFunction<EventT, String> topicNameMapper) Specify the JMS topic destination name where to send messages to dynamically.withUsername
(String username) Define the username to connect to the JMS broker (authenticated).withValueMapper
(SerializableBiFunction<EventT, javax.jms.Session, javax.jms.Message> valueMapper) Map theEventT
object to aMessage
.Methods inherited from class org.apache.beam.sdk.transforms.PTransform
addAnnotation, compose, compose, getAdditionalInputs, getAnnotations, getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, getResourceHints, populateDisplayData, setDisplayData, setResourceHints, toString, validate, validate
-
Constructor Details
-
Write
public Write()
-
-
Method Details
-
withConnectionFactory
Specify the JMS connection factory to connect to the JMS broker.The
ConnectionFactory
object has to be serializable, if it is not consider using thewithConnectionFactoryProviderFn(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Void, ? extends javax.jms.ConnectionFactory>)
For instance:
.apply(JmsIO.write().withConnectionFactory(myConnectionFactory)
- Specified by:
withConnectionFactory
in interfaceJmsIO.ConnectionFactoryContainer<EventT>
- Parameters:
connectionFactory
- The JMSConnectionFactory
.- Returns:
- The corresponding
JmsIO.Read
.
-
withConnectionFactoryProviderFn
public JmsIO.Write<EventT> withConnectionFactoryProviderFn(SerializableFunction<Void, ? extends javax.jms.ConnectionFactory> connectionFactoryProviderFn) Specify a JMS connection factory provider function to connect to the JMS broker. Use this method in case yourConnectionFactory
objects are themselves not serializable, but you can recreate them as needed with aSerializableFunction
providerFor instance:
pipeline.apply(JmsIO.write().withConnectionFactoryProviderFn(() -> new MyJmsConnectionFactory());
- Specified by:
withConnectionFactoryProviderFn
in interfaceJmsIO.ConnectionFactoryContainer<EventT>
- Parameters:
connectionFactoryProviderFn
- aSerializableFunction
that creates aConnectionFactory
- Returns:
- The corresponding
JmsIO.Write
-
withQueue
Specify the JMS queue destination name where to send messages to. TheJmsIO.Write
acts as a producer on the queue.This method is exclusive with
withTopic(String)
. The user has to specify a destination: queue, topic, or topicNameMapper.For instance:
.apply(JmsIO.write().withQueue("my-queue")
- Parameters:
queue
- The JMS queue name where to send messages to.- Returns:
- The corresponding
JmsIO.Read
.
-
withTopic
Specify the JMS topic destination name where to send messages to. TheJmsIO.Read
acts as a publisher on the topic.This method is exclusive with
withQueue(String)
. The user has to specify a destination: queue, topic, or topicNameMapper.For instance:
.apply(JmsIO.write().withTopic("my-topic")
- Parameters:
topic
- The JMS topic name.- Returns:
- The corresponding
JmsIO.Read
.
-
withUsername
Define the username to connect to the JMS broker (authenticated). -
withPassword
Define the password to connect to the JMS broker (authenticated). -
withTopicNameMapper
Specify the JMS topic destination name where to send messages to dynamically. TheJmsIO.Write
acts as a publisher on the topic.This method is exclusive with
withQueue(String)
andwithTopic(String)
. The user has to specify aSerializableFunction
that takesEventT
object as a parameter, and returns the topic name depending of the content of the event object.For example:
SerializableFunction<CompanyEvent, String> topicNameMapper = (event -> String.format( "company/%s/employee/%s", event.getCompanyName(), event.getEmployeeId()));
.apply(JmsIO.write().withTopicNameMapper(topicNameNapper)
- Parameters:
topicNameMapper
- The function returning the dynamic topic name.- Returns:
- The corresponding
JmsIO.Write
.
-
withValueMapper
public JmsIO.Write<EventT> withValueMapper(SerializableBiFunction<EventT, javax.jms.Session, javax.jms.Message> valueMapper) Map theEventT
object to aMessage
.For instance:
SerializableBiFunction<SomeEventObject, Session, Message> valueMapper = (e, s) -> { try { TextMessage msg = s.createTextMessage(); msg.setText(Mapper.MAPPER.toJson(e)); return msg; } catch (JMSException ex) { throw new JmsIOException("Error!!", ex); } };
.apply(JmsIO.write().withValueMapper(valueNapper)
- Parameters:
valueMapper
- The function returning theMessage
- Returns:
- The corresponding
JmsIO.Write
.
-
withRetryConfiguration
Specify the JMS retry configuration. TheJmsIO.Write
acts as a publisher on the topic.Allows a retry for failed published messages, the user should specify the maximum number of retries, a duration for retrying and a maximum cumulative retries. By default, the duration for retrying used is 15s and the maximum cumulative is 1000 days
RetryConfiguration
For example:
orRetryConfiguration retryConfiguration = RetryConfiguration.create(5);
orRetryConfiguration retryConfiguration = RetryConfiguration.create(5, Duration.standardSeconds(30), null);
RetryConfiguration retryConfiguration = RetryConfiguration.create(5, Duration.standardSeconds(30), Duration.standardDays(15));
.apply(JmsIO.write().withPublicationRetryPolicy(publicationRetryPolicy)
- Parameters:
retryConfiguration
- The retry configuration that should be used in case of failed publications.- Returns:
- The corresponding
JmsIO.Write
.
-
expand
Description copied from class:PTransform
Override this method to specify how thisPTransform
should be expanded on the givenInputT
.NOTE: This method should not be called directly. Instead apply the
PTransform
should be applied to theInputT
using theapply
method.Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
- Specified by:
expand
in classPTransform<PCollection<EventT>,
WriteJmsResult<EventT>>
-