Class RMQSink<IN>

  • Type Parameters:
    IN -
    All Implemented Interfaces:
    Serializable, org.apache.flink.api.common.functions.Function, org.apache.flink.api.common.functions.RichFunction, org.apache.flink.streaming.api.functions.sink.SinkFunction<IN>

    public class RMQSink<IN>
    extends org.apache.flink.streaming.api.functions.sink.RichSinkFunction<IN>
    A Sink for publishing data into RabbitMQ.
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.flink.streaming.api.functions.sink.SinkFunction

        org.apache.flink.streaming.api.functions.sink.SinkFunction.Context
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected com.rabbitmq.client.Channel channel  
      protected com.rabbitmq.client.Connection connection  
      protected String queueName  
      protected org.apache.flink.api.common.serialization.SerializationSchema<IN> schema  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void invoke​(IN value)
      Called when new data arrives to the sink, and forwards it to RMQ.
      void open​(org.apache.flink.configuration.Configuration config)  
      void setLogFailuresOnly​(boolean logFailuresOnly)
      Defines whether the producer should fail on errors, or only log them.
      protected com.rabbitmq.client.Connection setupConnection()
      Initializes the connection to RMQ using the default connection factory from setupConnectionFactory().
      protected com.rabbitmq.client.ConnectionFactory setupConnectionFactory()
      Initializes the connection to RMQ with a default connection factory.
      protected void setupQueue()
      Sets up the queue.
      • Methods inherited from class org.apache.flink.api.common.functions.AbstractRichFunction

        getIterationRuntimeContext, getRuntimeContext, setRuntimeContext
      • Methods inherited from interface org.apache.flink.streaming.api.functions.sink.SinkFunction

        finish, invoke, writeWatermark
    • Field Detail

      • connection

        protected transient com.rabbitmq.client.Connection connection
      • channel

        protected transient com.rabbitmq.client.Channel channel
      • schema

        protected org.apache.flink.api.common.serialization.SerializationSchema<IN> schema
    • Constructor Detail

      • RMQSink

        @PublicEvolving
        public RMQSink​(RMQConnectionConfig rmqConnectionConfig,
                       String queueName,
                       org.apache.flink.api.common.serialization.SerializationSchema<IN> schema)
        Parameters:
        rmqConnectionConfig - The RabbitMQ connection configuration RMQConnectionConfig.
        queueName - The queue to publish messages to.
        schema - A SerializationSchema for turning the Java objects received into bytes
      • RMQSink

        @PublicEvolving
        public RMQSink​(RMQConnectionConfig rmqConnectionConfig,
                       org.apache.flink.api.common.serialization.SerializationSchema<IN> schema,
                       RMQSinkPublishOptions<IN> publishOptions)
        Parameters:
        rmqConnectionConfig - The RabbitMQ connection configuration RMQConnectionConfig.
        schema - A SerializationSchema for turning the Java objects received into bytes
        publishOptions - A RMQSinkPublishOptions for providing message's routing key and/or properties In this case the computeMandatoy or computeImmediate MUST return false otherwise an IllegalStateException is raised during runtime.
      • RMQSink

        @PublicEvolving
        public RMQSink​(RMQConnectionConfig rmqConnectionConfig,
                       org.apache.flink.api.common.serialization.SerializationSchema<IN> schema,
                       RMQSinkPublishOptions<IN> publishOptions,
                       SerializableReturnListener returnListener)
        Parameters:
        rmqConnectionConfig - The RabbitMQ connection configuration RMQConnectionConfig.
        schema - A SerializationSchema for turning the Java objects received into bytes
        publishOptions - A RMQSinkPublishOptions for providing message's routing key and/or properties
        returnListener - A SerializableReturnListener implementation object to handle returned message event
    • Method Detail

      • setupQueue

        protected void setupQueue()
                           throws IOException
        Sets up the queue. The default implementation just declares the queue. The user may override this method to have a custom setup for the queue (i.e. binding the queue to an exchange or defining custom queue parameters)
        Throws:
        IOException
      • setLogFailuresOnly

        public void setLogFailuresOnly​(boolean logFailuresOnly)
        Defines whether the producer should fail on errors, or only log them. If this is set to true, then exceptions will be only logged, if set to false, exceptions will be eventually thrown and cause the streaming program to fail (and enter recovery).
        Parameters:
        logFailuresOnly - The flag to indicate logging-only on exceptions.
      • setupConnectionFactory

        protected com.rabbitmq.client.ConnectionFactory setupConnectionFactory()
                                                                        throws Exception
        Initializes the connection to RMQ with a default connection factory. The user may override this method to setup and configure their own ConnectionFactory.
        Throws:
        Exception
      • setupConnection

        protected com.rabbitmq.client.Connection setupConnection()
                                                          throws Exception
        Initializes the connection to RMQ using the default connection factory from setupConnectionFactory(). The user may override this method to setup and configure their own Connection.
        Throws:
        Exception
      • open

        public void open​(org.apache.flink.configuration.Configuration config)
                  throws Exception
        Specified by:
        open in interface org.apache.flink.api.common.functions.RichFunction
        Overrides:
        open in class org.apache.flink.api.common.functions.AbstractRichFunction
        Throws:
        Exception
      • invoke

        public void invoke​(IN value)
        Called when new data arrives to the sink, and forwards it to RMQ.
        Parameters:
        value - The incoming data
      • close

        public void close()
        Specified by:
        close in interface org.apache.flink.api.common.functions.RichFunction
        Overrides:
        close in class org.apache.flink.api.common.functions.AbstractRichFunction