Sha256: 06a8c40952b467d0cf199fcfcde5a56d9611c7b281332693f4ef608cc15a24b3

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

module Aggro
  module ZeroMQTransport
    # Public: Handles publishing messages on a given endpoint.
    class Publisher
      def initialize(endpoint)
        @endpoint = endpoint
      end

      def close_socket
        return unless @open && @pub_socket

        @pub_socket.close if @pub_socket
        @pub_socket = nil
        @open = false
      end

      def open_socket
        return @pub_socket if @open

        @open = true

        @pub_socket = ZeroMQTransport.context.socket(ZMQ::PUB)
        @pub_socket.setsockopt ZMQ::LINGER, 1_000
        @pub_socket.bind @endpoint

        @pub_socket
      end

      def publish(message)
        pub_socket.send_string message.to_s
      end

      private

      def pub_socket
        @pub_socket || open_socket
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aggro-0.0.4 lib/aggro/zeromq_transport/publisher.rb