/// <summary>
 /// Creates a new instance of the <see cref="DualSocketBusSubscriber"/> type.
 /// </summary>
 /// <param name="messageBusEndpoint"> The subscribed message bus' endpoint. </param>
 /// <param name="dispatcher"> The dispatcher that is used for incoming messages from the subscibed bus. </param>
 /// <param name="scheduler">
 /// An optional scheduler that can be used to deserialize incoming <see cref="NetMQMessage"/> instances on a separate thread.
 /// </param>
 protected DualSocketBusSubscriber(
     IDualSocketEndpoint messageBusEndpoint,
     ISocketDispatcherThread dispatcher,
     IScheduler?scheduler = null)
 {
     Dispatcher         = dispatcher;
     MessageBusEndpoint = messageBusEndpoint;
     IncomingMessages   = new Lazy <SubscriberSocket>(() =>
     {
         var incomingMessages = new SubscriberSocket();
         incomingMessages.SubscribeToAnyTopic();
         incomingMessages.Connect(MessageBusEndpoint.Outgoing);
         incomingMessages.ReceiveReady += OnIncomingMessageReceived;
         return(incomingMessages);
     }, true);
     Scheduler = scheduler;
 }
예제 #2
0
 /// <summary>
 /// Creates a new instance of the <see cref="DualSocketBus"/> type.
 /// </summary>
 /// <param name="endpoint"> The message bus' endpoint. </param>
 /// <param name="dispatcher"> The dispatcher that is used for incoming and outgoing messages. </param>
 protected DualSocketBus(IDualSocketEndpoint endpoint, ISocketDispatcherThread dispatcher)
 {
     Endpoint         = endpoint ?? throw new ArgumentNullException(nameof(endpoint));
     Dispatcher       = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
     IncomingMessages = new Lazy <SubscriberSocket>(() =>
     {
         var incomingMessages = new SubscriberSocket();
         incomingMessages.SubscribeToAnyTopic();
         incomingMessages.Bind(Endpoint.Incoming);
         incomingMessages.ReceiveReady += OnIncomingMessagesReceived;
         return(incomingMessages);
     }, true);
     OutgoingMessages = new Lazy <PublisherSocket>(() =>
     {
         var outgoingMessages = new PublisherSocket();
         outgoingMessages.Bind(Endpoint.Outgoing);
         return(outgoingMessages);
     }, true);
 }
 /// <summary>
 /// Creates a new instance of the <see cref="DualSocketBusPublisher"/> type.
 /// </summary>
 /// <param name="messageBusEndpoint"> The subscribed message bus' endpoint. </param>
 /// <param name="dispatcher"> The dispatcher that is used for outgoing messages from the subscibed bus. </param>
 public DualSocketBusPublisher(
     IDualSocketEndpoint messageBusEndpoint,
     ISocketDispatcherThread dispatcher)
 {
     Dispatcher         = dispatcher;
     MessageBusEndpoint = messageBusEndpoint;
     OutgoingMessages   = new Lazy <PublisherSocket>(() =>
     {
         var socket = new PublisherSocket();
         socket.Connect(MessageBusEndpoint.Incoming);
         return(socket);
     }, true);
     OutgoingMessageQueue = new Lazy <NetMQQueue <NetMQMessage> >(() =>
     {
         var queue           = new NetMQQueue <NetMQMessage>();
         queue.ReceiveReady += OnMessageQueued;
         return(queue);
     }, true);
 }