Esempio n. 1
0
        internal void GivenInstrument_WithSubscriber_PublishesMessage()
        {
            // Arrange
            this.publisher.Start();
            Task.Delay(100).Wait(); // Allow publisher to start

            var instrument = StubInstrumentProvider.AUDUSD();

            var subscriber = new SubscriberSocket(TestAddress);

            subscriber.Connect(TestAddress);
            subscriber.Subscribe(nameof(Instrument) + ":" + instrument.Symbol.Value);
            Task.Delay(100).Wait();

            // Act
            this.publisher.Endpoint.SendAsync(instrument);

            var topic   = subscriber.ReceiveFrameBytes();
            var message = subscriber.ReceiveFrameBytes();

            // Assert
            Assert.Equal("Instrument:AUD/USD.FXCM", Encoding.UTF8.GetString(topic));
            Assert.Equal(instrument, this.instrumentSerializer.Deserialize(message));

            // Tear Down
            subscriber.Disconnect(TestAddress);
            subscriber.Dispose();
            this.publisher.Stop().Wait();
            this.publisher.Dispose();
        }
Esempio n. 2
0
        private void RealTimeDataSocketReceiveReady(object sender, NetMQSocketEventArgs e)
        {
            lock (_realTimeDataSocketLock)
            {
                if (_realTimeDataSocket == null)
                {
                    return;
                }

                bool hasMore;

                _realTimeDataSocket.ReceiveFrameBytes(out hasMore);

                if (hasMore)
                {
                    var buffer = _realTimeDataSocket.ReceiveFrameBytes();

                    using (var ms = new MemoryStream())
                    {
                        var bar = MyUtils.ProtoBufDeserialize <RealTimeDataEventArgs>(buffer, ms);

                        RaiseEvent(RealTimeDataReceived, null, bar);
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        ///     Subscription worker
        ///     - Creates ZMQ subscriber socket and listens for specified frames
        /// </summary>
        private void SubscribeWorker()
        {
            using (var subscriber = new SubscriberSocket())
            {
                subscriber.Connect(_zmqConnectTo);
                subscriber.Subscribe(_zmqSubscribeTopic);
                Console.WriteLine("Subscribed to ZeroMQ '" + _zmqConnectTo + "' publisher for '" + _zmqSubscribeTopic + "' frames.");

                while (true)
                {
                    // we expect the publisher to sends 3 frames per data packet
                    // first, the header frame
                    var replyHeader = subscriber.ReceiveFrameString();
                    if (replyHeader != _zmqSubscribeTopic)
                    {
                        Console.WriteLine("Unexpected Frame Header! '" + _zmqSubscribeTopic + "' expected, but received " + replyHeader +
                                          ". Skipping and waiting for proper frame header.");
                        continue;
                    }

                    // next, the data frame
                    var replyFrame = subscriber.ReceiveFrameBytes();

                    // last, the reply counter frame
                    var replyCounter = BitConverter.ToInt32(subscriber.ReceiveFrameBytes(), 0);
                    // Console.WriteLine("counter: " + replyCounter);

                    // pass the received data to our consumer thread
                    _consumer.EnqueueTask(replyFrame, replyCounter);
                }
            }
        }
Esempio n. 4
0
        internal void GivenTickMessage_WithSubscriber_PublishesMessage()
        {
            // Arrange
            var symbol = new Symbol("AUDUSD", new Venue("FXCM"));

            var subscriber = new SubscriberSocket(TestAddress);

            subscriber.Connect(TestAddress);
            subscriber.Subscribe($"Quote:{symbol.Value}");

            Task.Delay(100).Wait();  // Allow subscribers to connect

            var tick = StubQuoteTickProvider.Create(symbol);

            // Act
            this.publisher.Endpoint.SendAsync(tick).Wait();

            var topic   = subscriber.ReceiveFrameBytes();
            var message = subscriber.ReceiveFrameBytes();

            // Assert
            Assert.Equal(1, this.publisher.SentCount);
            Assert.Equal("Quote:AUDUSD.FXCM", Encoding.UTF8.GetString(topic));
            Assert.Equal(tick.ToSerializableString(), Encoding.UTF8.GetString(message));

            // Tear Down
            subscriber.Disconnect(TestAddress);
            subscriber.Dispose();
            this.publisher.Stop().Wait();
            this.publisher.Dispose();
        }
Esempio n. 5
0
        /// <summary>
        ///     Subscription worker
        ///     - Creates ZMQ subscriber socket and listens for specified frames
        /// </summary>
        private void SubscribeWorker()
        {
            using (var subscriber = new SubscriberSocket())
            {
                subscriber.Connect(_connectTo.AbsoluteUri.TrimEnd('/'));
                subscriber.Subscribe(_subscribeTopic);
                Console.WriteLine("Subscribed to ZeroMQ '" + _connectTo + "' publisher for '" + _subscribeTopic + "' frames.");

                while (true)
                {
                    // the publisher sends 3 frames per data packet
                    // first, the header frame
                    var replyHeader = subscriber.ReceiveFrameString();
                    // if this is not a valid header frame, continue to next frame
                    if (replyHeader != _subscribeTopic)
                    {
                        Console.WriteLine("Unexpected Frame Header! '" + _subscribeTopic + "' expected, but received " + replyHeader +
                                          ". Skipping and waiting for proper frame header.");
                        continue;
                    }

                    // next, the data frame
                    var replyFrame = subscriber.ReceiveFrameBytes();

                    // last, the reply counter frame
                    var replyCounter = BitConverter.ToInt32(subscriber.ReceiveFrameBytes(), 0);

                    // pass the received data to callback function
                    _callback(replyHeader, replyFrame, replyCounter);
                }
            }
        }
Esempio n. 6
0
        private void HandleNextConsumer()
        {
            using (_consumerSocket = new SubscriberSocket())
            {
                _consumerSocket.Options.ReceiveHighWatermark = 1000;
                _consumerSocket.Connect(_currentProducer.Endpoint);
                _consumerSocket.Subscribe(_consumerConfiguration.Topic);

                while (!_cancel.IsCancellationRequested && !_currentConsumerTaskCancellation.IsCancellationRequested)
                {
                    var topic            = _consumerSocket.ReceiveFrameString();
                    var messageBytes     = _consumerSocket.ReceiveFrameBytes();
                    var transportMessage = JsonConvert.DeserializeObject <TransportMessage>(Encoding.UTF32.GetString(messageBytes));

                    if (transportMessage.MessageType != typeof(TEvent))
                    {
                        throw new InvalidOperationException($"wrong event type {transportMessage.MessageType} vs expected {typeof(TEvent)}");
                    }

                    var message = (TEvent)JsonConvert.DeserializeObject(Encoding.UTF32.GetString(transportMessage.Message), transportMessage.MessageType);

                    _subject.OnNext(message);
                }
            }
        }
        private void FilteredBackgroundWorker(object sender, DoWorkEventArgs e)
        {
            var filter = (string)e.Argument;

            using (var subscriberSocket = new SubscriberSocket())
            {
                subscriberSocket.Options.ReceiveHighWatermark = 1000;
                subscriberSocket.Connect(transportMethod + "eventsystem");
                subscriberSocket.Subscribe(filter);
                while (!e.Cancel)
                {
                    string messageTopicReceived = subscriberSocket.ReceiveFrameString();
                    byte[] message      = subscriberSocket.ReceiveFrameBytes();
                    var    eventMessage = EventMessage.Create(message);

                    Debug.Log("Event received for " + filter + "|" + messageTopicReceived);

                    foreach (var actionDelegate in subscriberDelegates[filter])
                    {
                        try
                        {
                            actionDelegate.Invoke(eventMessage.Sender, eventMessage.Parameter);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        private void Run()
        {
            while (isRunning)
            {
                try
                {
                    bool hasMore;
                    var  clientIdString = subscribeSocket.ReceiveFrameString(out hasMore);

                    if (hasMore)
                    {
                        var receiedBuffer = subscribeSocket.ReceiveFrameBytes(out hasMore);

                        if (!hasMore && receiedBuffer != null && receiedBuffer.Length > 0)
                        {
                            var deserialized = serializer.Deserialize <ServerToClientMessage>(receiedBuffer);
                            if (deserialized != null && messageHandler != null)
                            {
                                messageHandler(deserialized);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Esempio n. 9
0
        private void ThreadSub()
        {
            List <SubscriberSocket> socklist = new List <SubscriberSocket>();
            var sock = new SubscriberSocket();

            sock.Options.IPv4Only = true;
            sock.SubscribeToAnyTopic();

            foreach (var port in PortList)
            {
                string addr = $"tcp://{IPAddress.Loopback}:{port}";
                sock.Connect(addr);
            }

            Thread.Sleep(2000);

            while (EventStop.Wait(WaitInterval) == false)
            {
                var    buffer = sock.ReceiveFrameBytes();
                string msg    = Encoding.Unicode.GetString(buffer);
                textBox1.AppendLine(msg);
            }

            sock.Close();
        }
Esempio n. 10
0
        public async Task ListenToEddn()
        {
            var utf8 = new UTF8Encoding();

            using (var client = new SubscriberSocket())
            {
                client.Options.ReceiveHighWatermark = 1000;
                client.Connect("tcp://eddn.edcd.io:9500");
                client.SubscribeToAnyTopic();
                while (true)
                {
                    var bytes        = client.ReceiveFrameBytes();
                    var uncompressed = ZlibStream.UncompressBuffer(bytes);

                    var result = utf8.GetString(uncompressed);

                    // ignore all outfitting and commodity responses
                    if (!result.Contains(@"""Influence"""))
                    {
                        continue;
                    }

                    Submissions.Add(EddnRequest.FromJson(result));
                }
            }
        }
Esempio n. 11
0
        public void SubscriberData(List <string> topics = null)
        {
            SubscriberSocket subscriber = Create(addrPoint);

            Register(subscriber, topics);
            Task.Factory.StartNew(() =>
            {
                try
                {
                    while (true)
                    {
                        string messageTopicReceived = subscriber.ReceiveFrameString();
                        byte[] dataReceived         = subscriber.ReceiveFrameBytes();
                        if (MyFuncOfFlag.IsEndOfFlag(dataReceived))
                        {
                            break;
                        }
                        Notify(messageTopicReceived, dataReceived);
                    }
                }
                catch { }
                finally
                {
                    Unregister(subscriber, topics);
                }
            });
        }
Esempio n. 12
0
        public void MultipleLargeMessages()
        {
            var largeMessage = new byte[12000];

            for (int i = 0; i < 12000; i++)
            {
                largeMessage[i] = (byte)(i % 256);
            }

            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    var port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);
                    sub.Subscribe("");

                    Thread.Sleep(1000);

                    pub.SendFrame("");
                    sub.SkipFrame();

                    for (int i = 0; i < 100; i++)
                    {
                        pub.SendFrame(largeMessage);

                        byte[] recvMesage = sub.ReceiveFrameBytes();

                        for (int j = 0; j < 12000; j++)
                        {
                            Assert.AreEqual(largeMessage[j], recvMesage[j]);
                        }
                    }
                }
        }
Esempio n. 13
0
        public void LargerBufferLength()
        {
            var largerBuffer = new byte[256];

            {
                largerBuffer[124] = 0xD;
                largerBuffer[125] = 0xE;
                largerBuffer[126] = 0xE;
                largerBuffer[127] = 0xD;
            }

            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    var port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);
                    sub.Subscribe("");

                    Thread.Sleep(100);

                    pub.SendFrame(largerBuffer, 128);

                    byte[] recvMesage = sub.ReceiveFrameBytes();

                    Assert.AreEqual(128, recvMesage.Length);
                    Assert.AreEqual(0xD, recvMesage[124]);
                    Assert.AreEqual(0xE, recvMesage[125]);
                    Assert.AreEqual(0xE, recvMesage[126]);
                    Assert.AreEqual(0xD, recvMesage[127]);

                    Assert.AreNotEqual(largerBuffer.Length, recvMesage.Length);
                }
        }
Esempio n. 14
0
 void Run()
 {
     while (_running)
     {
         try
         {
             string topic;
             if (_subSocket.TryReceiveFrameString(TimeSpan.FromMilliseconds(100), out topic))
             {
                 var eventName       = _subSocket.ReceiveFrameString();
                 var messageReceived = _subSocket.ReceiveFrameBytes();
                 try
                 {
                     MessaggioRicevuto(eventName, messageReceived);
                 }
                 catch
                 {
                 }
             }
         }
         catch (Exception ex)
         {
             if (_running)
             {
                 Console.WriteLine(this.GetType().Name + " : " + ex.Message);
             }
         }
     }
 }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var utf8 = new UTF8Encoding();

            try
            {
                using (var client = new SubscriberSocket())
                {
                    client.Options.ReceiveHighWatermark = 1000;
                    client.Connect("tcp://eddn.edcd.io:9500");
                    client.SubscribeToAnyTopic();
                    while (true)
                    {
                        var bytes        = client.ReceiveFrameBytes();
                        var uncompressed = ZlibStream.UncompressBuffer(bytes);

                        var result = utf8.GetString(uncompressed);

                        addmessage(result);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.Read();
            }
        }
Esempio n. 16
0
        public void LargeMessage()
        {
            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    pub.Connect("pgm://224.0.0.1:5555");
                    sub.Bind("pgm://224.0.0.1:5555");

                    sub.Subscribe("");

                    var data = new byte[3200]; // this should be at least 3 packets

                    for (Int16 i = 0; i < 1600; i++)
                    {
                        Array.Copy(BitConverter.GetBytes(i), 0, data, i * 2, 2);
                    }

                    pub.SendFrame(data);

                    byte[] message = sub.ReceiveFrameBytes();

                    Assert.AreEqual(3200, message.Length);

                    for (Int16 i = 0; i < 1600; i++)
                    {
                        Assert.AreEqual(i, BitConverter.ToInt16(message, i * 2));
                    }
                }
        }
Esempio n. 17
0
        internal void Test_can_publish_events()
        {
            // Arrange
            const string testAddress = "tcp://127.0.0.1:56601";

            var publisher = new EventPublisher(
                this.container,
                new MsgPackEventSerializer(),
                new BypassCompressor(),
                EncryptionSettings.None(),
                new Label("test-publisher"),
                new Port(56601));

            publisher.Start().Wait();

            var subscriber = new SubscriberSocket(testAddress);

            subscriber.Connect(testAddress);
            subscriber.Subscribe("Event:Trade:TESTER-001");

            Task.Delay(100).Wait(); // Allow socket to subscribe

            var serializer = new MsgPackEventSerializer();
            var order      = new StubOrderBuilder().BuildMarketOrder();
            var rejected   = StubEventMessageProvider.OrderRejectedEvent(order);
            var tradeEvent = new TradeEvent(TraderId.FromString("TESTER-001"), rejected);

            // Act
            publisher.Endpoint.Send(tradeEvent);
            this.Output.WriteLine("Waiting for published events...");

            var topic   = subscriber.ReceiveFrameBytes();
            var message = subscriber.ReceiveFrameBytes();
            var @event  = serializer.Deserialize(message);

            // Assert
            Assert.Equal("Event:Trade:TESTER-001", Encoding.UTF8.GetString(topic));
            Assert.Equal(typeof(OrderRejected), @event.GetType());

            // Tear Down
            subscriber.Disconnect(testAddress);
            subscriber.Dispose();
            publisher.Stop().Wait();
            publisher.Dispose();
        }
Esempio n. 18
0
        public static T Deserialise <T>(this SubscriberSocket subscriberSocket)
        {
            var messageReceived = subscriberSocket.ReceiveFrameBytes();

            using (BsonReader reader = new BsonReader(new MemoryStream(messageReceived)))
            {
                JsonSerializer serializer = new JsonSerializer();
                return(serializer.Deserialize <T>(reader));
            }
        }
Esempio n. 19
0
        public void Sending1000Messages()
        {
            // creating two different context and sending 1000 messages

            int count = 0;

            var subReady = new ManualResetEvent(false);

            Task subTask = Task.Factory.StartNew(() =>
            {
                using (var sub = new SubscriberSocket())
                {
                    sub.Bind("pgm://224.0.0.1:5555");
                    sub.Subscribe("");

                    subReady.Set();

                    while (count < 1000)
                    {
                        bool more;
                        Assert.AreEqual(count, BitConverter.ToInt32(sub.ReceiveFrameBytes(out more), 0));
                        Assert.IsFalse(more);
                        count++;
                    }
                }
            });

            subReady.WaitOne();

            Task pubTask = Task.Factory.StartNew(() =>
            {
                using (var pub = new PublisherSocket())
                {
                    pub.Connect("pgm://224.0.0.1:5555");

                    for (int i = 0; i < 1000; i++)
                    {
                        pub.SendFrame(BitConverter.GetBytes(i));
                    }

                    // if we close the socket before the subscriber receives all messages subscriber
                    // might miss messages, lets wait another second
                    Thread.Sleep(1000);
                }
            });

            pubTask.Wait();
            subTask.Wait();

            Thread.MemoryBarrier();

            Assert.AreEqual(1000, count);
        }
Esempio n. 20
0
        public byte[] NetMQReceiveBytes(string connectionString)
        {
            using (SubscriberSocket subSocket = new SubscriberSocket())
            {
                subSocket.Connect(connectionString);

                subSocket.Subscribe(String.Empty);
                byte[] result = subSocket.ReceiveFrameBytes();

                return(result);
            }
        }
Esempio n. 21
0
        internal void GivenMessageToPublish_WhenMessageValid_PublishesToSubscriber()
        {
            // Arrange
            var publisher = new MockDataPublisher(
                this.container,
                DataBusFactory.Create(this.container),
                EncryptionSettings.None(),
                ZmqNetworkAddress.LocalHost(new Port(55555)));

            publisher.Start().Wait();

            const string testAddress = "tcp://localhost:55555";
            var          subscriber  = new SubscriberSocket(testAddress);

            subscriber.Connect(testAddress);
            subscriber.Subscribe(TestTopic);

            Task.Delay(100).Wait(); // Allow sockets to subscribe

            // Act
            const string toSend = "1234,1234";

            publisher.Endpoint.SendAsync((TestTopic, toSend));

            var topic   = subscriber.ReceiveFrameBytes();
            var message = subscriber.ReceiveFrameBytes();

            // Assert
            Assert.Equal(TestTopic, Encoding.UTF8.GetString(topic));
            Assert.Equal(toSend, Encoding.UTF8.GetString(message));
            Assert.Equal(ComponentState.Running, publisher.ComponentState);
            Assert.Equal(1, publisher.SentCount);

            // Tear Down
            subscriber.Disconnect(testAddress);
            subscriber.Dispose();
            publisher.Stop().Wait();
            publisher.Dispose();
        }
Esempio n. 22
0
        public async Task TestProducer()
        {
            var cancel = new CancellationTokenSource();
            SubscriberSocket _subSocket = null;

            var serializer = new EventSerializer();
            var messages   = new List <AccidentEvent>();

            var directory     = new Directory();
            var configuration = new ProducerConfiguration()
            {
                IsTest   = true,
                Endpoint = "tcp://localhost:8080",
                Id       = Guid.NewGuid()
            };

            var producer = new AccidentProducer(configuration, directory, new JsonSerializerSettings());

            producer.Start();

            await Task.Delay(500);

            new Task(() =>
            {
                using (_subSocket = new SubscriberSocket())
                {
                    _subSocket.Options.ReceiveHighWatermark = 1000;
                    _subSocket.Connect("tcp://localhost:8080");
                    _subSocket.Subscribe("Paris");

                    while (!cancel.IsCancellationRequested)
                    {
                        var topic            = _subSocket.ReceiveFrameString();
                        var messageBytes     = _subSocket.ReceiveFrameBytes();
                        var transportMessage = JsonConvert.DeserializeObject <TransportMessage>(Encoding.UTF32.GetString(messageBytes));
                        var message          = (AccidentEvent)JsonConvert.DeserializeObject(Encoding.UTF32.GetString(transportMessage.Message), transportMessage.MessageType);
                        messages.Add(message);
                    }
                }
            }, cancel.Token).Start();


            await Task.Delay(1000);

            Assert.Greater(messages.Count, 0);
            Assert.IsTrue(messages.All(m =>
            {
                return(serializer.Serialize(m).StartsWith("Paris."));
            }));
        }
Esempio n. 23
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _subscriberSocket.Connect(_options.Address);
            _subscriberSocket.SubscribeToAnyTopic();
            while (true)
            {
                var bytesReceived = _subscriberSocket.ReceiveFrameBytes();
                var uncompressed  = ZlibStream.UncompressBuffer(bytesReceived);
                var entity        = _encoding.GetString(uncompressed);
                await _importTargetFactory.ImportAsync(entity);

                _logger.LogInformation(entity);
            }
        }
Esempio n. 24
0
    /// <summary>
    /// Function that is called by Poller Object when a data is received.
    /// Data Contains both topic and user data in the order .
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Subscriber_ReceiveReady(object sender, NetMQSocketEventArgs e)
    {
        var topic = Subscriber.ReceiveFrameString();
        var msg   = Subscriber.ReceiveFrameBytes();

        if (msg == null)
        {
            System.Diagnostics.Debug.WriteLine("Subscriber : Received data is null! Topic:" + topic);
            return;
        }
        if (OnDataReceived != null)
        {
            OnDataReceived(msg);
        }
    }
Esempio n. 25
0
 public void PubSub()
 {
     ThreadPool.QueueUserWorkItem(state => {
         var client = new SubscriberSocket();
         client.Connect("tcp://" + IP + ":5556");
         while (!_stopLoops)
         {
             try {
                 var receiveFrame = client.ReceiveFrameBytes();
                 var @event       = Serializer.Deserialize <Event>(new MemoryStream(receiveFrame));
             }
             catch (Exception e) {
                 Console.WriteLine(e);
             }
         }
     });
 }
Esempio n. 26
0
    private void EventTask(string channel)
    {
        Debug.Log("Start event thread on chanel " + channel);

        var address = string.Format(">tcp://{0}:{1}", serverIp, eventPort);

        using (var subscriber = new SubscriberSocket(address))
        {
            // Listen to all topics
            subscriber.Subscribe(channel);
            while (true)
            {
                var eventPacket = subscriber.ReceiveFrameBytes();

                EnqueueEvent(eventPacket);
            }
        }
    }
Esempio n. 27
0
        static void Main(string[] args)
        {
            string uuid = "A";

            using (var subSocket = new SubscriberSocket())
            {
                subSocket.Connect("tcp://192.168.1.106:5555");
                // subSocket.Options.ReceiveHighWatermark = 0;
                subSocket.Subscribe(uuid);
                Console.WriteLine("Subscriber socket connecting...");
                while (true)
                {
                    string uuid_value = subSocket.ReceiveFrameString();
                    byte[] RMSValue   = subSocket.ReceiveFrameBytes();
                    string result     = string.Concat(Enumerable.Repeat("#", (int)(Math.Round((BitConverter.ToDouble(RMSValue, 0) * 200)))));
                    Console.WriteLine(result);
                }
            }
        }
Esempio n. 28
0
 public void Subscriber <T>(List <string> topics = null)
 {
     if (typeof(T) == typeof(byte[]))
     {
         SubscriberData(topics);
     }
     else if (typeof(T) == typeof(string))
     {
         SubscriberString(topics);
     }
     else
     {
         SubscriberSocket subscriber = Create(addrPoint);
         Register(subscriber, topics);
         Task.Factory.StartNew(() =>
         {
             try
             {
                 while (true)
                 {
                     string messageTopicReceived = subscriber.ReceiveFrameString();
                     byte[] dataReceived         = subscriber.ReceiveFrameBytes();
                     if (MyFuncOfFlag.IsEndOfFlag(dataReceived))
                     {
                         break;
                     }
                     using (MemoryStream stream = new MemoryStream())
                     {
                         stream.Write(dataReceived, 0, dataReceived.Length);
                         stream.Seek(0, SeekOrigin.Begin);
                         Notify(messageTopicReceived, (T) new BinaryFormatter().Deserialize(stream));
                     }
                 }
             }
             catch { }
             finally
             {
                 Unregister(subscriber, topics);
             }
         });
     }
 }
Esempio n. 29
0
        public void LargeMessage()
        {
            using (var pub = new PublisherSocket())
                using (var sub = new SubscriberSocket())
                {
                    var port = pub.BindRandomPort("tcp://127.0.0.1");
                    sub.Connect("tcp://127.0.0.1:" + port);
                    sub.Subscribe("");

                    Thread.Sleep(100);

                    var msg = new byte[300];

                    pub.SendFrame(msg);

                    byte[] msg2 = sub.ReceiveFrameBytes();

                    Assert.AreEqual(300, msg2.Length);
                }
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            var utf8 = new UTF8Encoding();

            using (var client = new SubscriberSocket())
            {
                client.Options.ReceiveHighWatermark = 1000;
                client.Connect("tcp://cedar.canonn.tech:9500");
                client.SubscribeToAnyTopic();
                while (true)
                {
                    var bytes        = client.ReceiveFrameBytes();
                    var uncompressed = ZlibStream.UncompressBuffer(bytes);

                    var result = utf8.GetString(uncompressed);

                    Console.WriteLine(result);
                }
            }
        }