Beispiel #1
0
        /// <summary>
        /// Wrap a message with the identity and an empty frame
        /// </summary>
        /// <returns>new created message</returns>
        private static NetMQMessage Wrap(NetMQFrame identity, NetMQMessage msg)
        {
            var result = new NetMQMessage(msg);

            result.PushEmptyFrame();
            result.Push(identity);

            return(result);
        }
Beispiel #2
0
        public void EmptyFrames()
        {
            var message = new NetMQMessage();

            message.Append("middle");
            message.AppendEmptyFrame();
            message.PushEmptyFrame();

            Assert.AreEqual("middle", message[1].ConvertToString());
            Assert.AreEqual(0, message[0].MessageSize);
            Assert.AreEqual(0, message[2].MessageSize);
            Assert.AreEqual(3, message.FrameCount);
        }
Beispiel #3
0
        public void EmptyFrames()
        {
            var message = new NetMQMessage();

            message.Append("middle");
            message.AppendEmptyFrame();
            message.PushEmptyFrame();

            Assert.AreEqual("middle", message[1].ConvertToString());
            Assert.AreEqual(0, message[0].MessageSize);
            Assert.AreEqual(0, message[2].MessageSize);
            Assert.AreEqual(3, message.FrameCount);
        }
Beispiel #4
0
        public void IsValidTopicMessage_WithNoData_IsFalse()
        {
            // Arrange
            var messageFactory = new NetMQMessageFactory(serializerCache, packageFactory);
            var message        = new NetMQMessage(2);

            message.Push("Topic");
            message.PushEmptyFrame();

            // Act
            var isValid = messageFactory.IsValidTopicMessage(message);

            // Assert
            Assert.That(isValid, Is.False);
        }
Beispiel #5
0
        private void SendSnapshot(object sender, NetMQSocketEventArgs e)
        {
            var    message = e.Socket.ReceiveMultipartMessage();
            string topic   = message.Last.ConvertToString();

            var snapshot = _snapshotGenerator.GenerateSnapshot(topic);

            var response = new NetMQMessage(snapshot);

            response.PushEmptyFrame();
            response.Push(message.First);

            //TODO: consider sendmoreframe to stream the snapshot
            e.Socket.SendMultipartMessage(response);
        }
Beispiel #6
0
        /// <summary>
        ///     send a asyncronous request to a broker for a specific service without receiving a reply
        ///
        ///     there is no retry logic
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <exception cref="ApplicationException">serviceName must not be empty or null.</exception>
        /// <exception cref="ApplicationException">the request must not be null</exception>
        public Guid Send([NotNull] string serviceName, NetMQMessage request, SendOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ApplicationException("serviceName must not be empty or null.");
            }

            if (ReferenceEquals(request, null))
            {
                throw new ApplicationException("the request must not be null");
            }

            if (ReferenceEquals(options, null))
            {
                options.Timeout  = m_defaultTimeOutPerRequest;
                options.Attempts = 1;
            }

            // memorize it for the event handler
            m_serviceName = serviceName; // TODO this is wrong because I can be sending multiple serviceNames

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
            {
                Connect();
            }

            var message = new NetMQMessage(request);

            // prefix the request according to MDP specs
            // Frame 1: Empty Frame, because DEALER socket needs to emulate a REQUEST socket to comunicate with ROUTER socket
            // Frame 2: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 3: service name as printable string
            // Frame 4: request

            message.Push(serviceName);
            message.Push(m_mdpClient);
            message.PushEmptyFrame();

            var req   = new Request(serviceName, message, options.Timeout, options.Attempts);
            var reqId = m_requestQueue.EnqueueRequest(req);

            Log($"[CLIENT INFO] sending requestId: {reqId} message: {message} to service {serviceName}");
            return(reqId);
        }
Beispiel #7
0
        /// <summary>
        ///     send a asyncronous request to a broker for a specific service without receiving a reply
        ///
        ///     there is no retry logic
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <exception cref="ApplicationException">serviceName must not be empty or null.</exception>
        /// <exception cref="ApplicationException">the request must not be null</exception>
        public void Send([NotNull] string serviceName, NetMQMessage request)
        {
            // TODO criar tabela de pedidos ongoing

            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ApplicationException("serviceName must not be empty or null.");
            }

            if (ReferenceEquals(request, null))
            {
                throw new ApplicationException("the request must not be null");
            }

            // memorize it for the event handler
            m_serviceName = serviceName;

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
            {
                Connect();
            }

            var message = new NetMQMessage(request);

            // prefix the request according to MDP specs
            // Frame 1: Empty Frame, because DEALER socket needs to emulate a REQUEST socket to comunicate with ROUTER socket
            // Frame 2: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 3: service name as printable string
            // Frame 4: request
            message.Push(serviceName);
            message.Push(m_mdpClient);
            message.PushEmptyFrame();

            Log($"[CLIENT INFO] sending message to service {serviceName}");

            m_client.SendMultipartMessage(message); // Or TrySend!? ErrorHandling!?
        }
Beispiel #8
0
        /// <summary>
        ///     send a asyncronous request to a broker for a specific service without receiving a reply
        ///     
        ///     there is no retry logic
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <exception cref="ApplicationException">serviceName must not be empty or null.</exception>
        /// <exception cref="ApplicationException">the request must not be null</exception>
        public void Send([NotNull] string serviceName, NetMQMessage request)
        {
            // TODO criar tabela de pedidos ongoing

            if (string.IsNullOrWhiteSpace(serviceName))
                throw new ApplicationException("serviceName must not be empty or null.");

            if (ReferenceEquals(request, null))
                throw new ApplicationException("the request must not be null");

            // memorize it for the event handler
            m_serviceName = serviceName;

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
                Connect();

            var message = new NetMQMessage(request);
            // prefix the request according to MDP specs
            // Frame 1: Empty Frame, because DEALER socket needs to emulate a REQUEST socket to comunicate with ROUTER socket
            // Frame 2: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 3: service name as printable string
            // Frame 4: request
            message.Push(serviceName);
            message.Push(m_mdpClient);
            message.PushEmptyFrame();

            Log($"[CLIENT INFO] sending {message} to service {serviceName}");

            m_client.SendMultipartMessage(message); // Or TrySend!? ErrorHandling!?
        }
Beispiel #9
0
        /// <summary>
        /// Wrap a message with the identity and an empty frame
        /// </summary>
        /// <returns>new created message</returns>
        private static NetMQMessage Wrap(NetMQFrame identity, NetMQMessage msg)
        {
            var result = new NetMQMessage(msg);

            result.PushEmptyFrame();
            result.Push(identity);

            return result;
        }
Beispiel #10
0
        /// <summary>
        ///     send a asyncronous request to a broker for a specific service without receiving a reply
        ///     
        ///     there is no retry logic
        ///     according to the verbose flag it reports about its activities
        /// </summary>
        /// <param name="serviceName">the name of the service requested</param>
        /// <param name="request">the request message to process by service</param>
        /// <exception cref="ApplicationException">serviceName must not be empty or null.</exception>
        /// <exception cref="ApplicationException">the request must not be null</exception>
        public Guid Send([NotNull] string serviceName, NetMQMessage request, SendOptions options = null)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
                throw new ApplicationException("serviceName must not be empty or null.");

            if (ReferenceEquals(request, null))
                throw new ApplicationException("the request must not be null");

            if (ReferenceEquals(options, null))
            {
                options.Timeout = m_defaultTimeOutPerRequest;
                options.Attempts = 1;
            }

            // memorize it for the event handler
            m_serviceName = serviceName; // TODO this is wrong because I can be sending multiple serviceNames

            // if for any reason the socket is NOT connected -> connect it!
            if (!m_connected)
                Connect();

            var message = new NetMQMessage(request);
            // prefix the request according to MDP specs
            // Frame 1: Empty Frame, because DEALER socket needs to emulate a REQUEST socket to comunicate with ROUTER socket
            // Frame 2: "MDPCxy" (six bytes MDP/Client x.y)
            // Frame 3: service name as printable string
            // Frame 4: request

            message.Push(serviceName);
            message.Push(m_mdpClient);
            message.PushEmptyFrame();

            var req = new Request(serviceName, message, options.Timeout, options.Attempts);
            var reqId = m_requestQueue.EnqueueRequest(req);
            Log($"[CLIENT INFO] sending requestId: {reqId} message: {message} to service {serviceName}");
            return reqId;
        }