Class JmsIO


  • public class JmsIO
    extends java.lang.Object
    An unbounded source for JMS destinations (queues or topics).

    Reading from a JMS destination

    JmsIO source returns unbounded collection of JMS records as PCollection<JmsRecord>. A JmsRecord includes JMS headers and properties, along with the JMS TextMessage payload.

    To configure a JMS source, you have to provide a ConnectionFactory and the destination (queue or topic) where to consume. The following example illustrates various options for configuring the source:

    
     pipeline.apply(JmsIO.read()
        .withConnectionFactory(myConnectionFactory)
        .withQueue("my-queue")
        // above two are required configuration, returns PCollection<JmsRecord>
    
        // rest of the settings are optional
    
     

    It is possible to read any type of JMS Message into a custom POJO using the following configuration:

    
     pipeline.apply(JmsIO.<T>readMessage()
        .withConnectionFactory(myConnectionFactory)
        .withQueue("my-queue")
        .withMessageMapper((MessageMapper<T>) message -> {
          // code that maps message to T
        })
        .withCoder(
          // a coder for T
        )
    
     

    Writing to a JMS destination

    JmsIO sink supports writing text messages to a JMS destination on a broker. To configure a JMS sink, you must specify a ConnectionFactory and a Destination name. For instance:

    
     pipeline
       .apply(...) // returns PCollection<String>
       .apply(JmsIO.write()
           .withConnectionFactory(myConnectionFactory)
           .withQueue("my-queue")