Esempio n. 1
0
        internal static Message FromMultipartMessage(MultipartMessage multipartMessage)
        {
            var(traceOptions, distributionPattern) = multipartMessage.GetTraceOptionsDistributionPattern();
            var(routes, hops) = multipartMessage.GetMessageRouting();

            return(new Message(multipartMessage.GetMessageIdentity(),
                               multipartMessage.GetMessageVersion().GetUShort(),
                               multipartMessage.GetMessagePartition())
            {
                WireFormatVersion = multipartMessage.GetWireFormatVersion().GetInt(),
                Body = multipartMessage.GetMessageBody(),
                TTL = multipartMessage.GetMessageTTL(),
                CorrelationId = multipartMessage.GetCorrelationId(),
                Signature = multipartMessage.GetSignature(),
                Domain = multipartMessage.GetDomain(),
                TraceOptions = traceOptions,
                Distribution = distributionPattern,
                CallbackReceiverIdentity = multipartMessage.GetCallbackReceiverIdentity(),
                CallbackReceiverNodeIdentity = multipartMessage.GetCallbackReceiverNodeIdentity(),
                CallbackPoint = multipartMessage.GetCallbackPoints(),
                CallbackKey = multipartMessage.GetCallbackKey(),
                ReceiverNodeIdentity = multipartMessage.GetReceiverNodeIdentity(),
                ReceiverIdentity = multipartMessage.GetReceiverIdentity(),
                routing = routes,
                Hops = hops
            });
        }
Esempio n. 2
0
        public IMessage ReceiveMessage(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                var message = new NetMQMessage();
                if (socket.TryReceiveMultipartMessage(ReceiveWaitTimeout, ref message))
                {
                    var multipart = new MultipartMessage(message);
                    return new Message(multipart);
                }
            }

            return null;
        }
Esempio n. 3
0
        public void TestMessageHops_AreConsistentlyTransferredViaMultipartMessage()
        {
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            var socketEnpoints = new[]
                                 {
                                     new SocketEndpoint(new Uri("tcp://localhost:40"), Guid.NewGuid().ToByteArray()),
                                     new SocketEndpoint(new Uri("tcp://localhost:40"), Guid.NewGuid().ToByteArray())
                                 };
            foreach (var socketEndpoint in socketEnpoints)
            {
                message.PushRouterAddress(socketEndpoint);
            }

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            CollectionAssert.AreEqual(socketEnpoints, message.GetMessageHops());
        }
Esempio n. 4
0
 public void SendMessage(IMessage message)
 {
     var multipart = new MultipartMessage((Message) message);
     socket.SendMultipartMessage(new NetMQMessage(multipart.Frames));
 }
Esempio n. 5
0
        public void TestMessageContent_IsConsistentlyTransferredViaMultipartMessage()
        {
            var messageText = Guid.NewGuid().ToString();
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage {Message = messageText}, SimpleMessage.MessageIdentity);

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            Assert.AreEqual(messageText, message.GetPayload<SimpleMessage>().Message);
            CollectionAssert.AreEqual(SimpleMessage.MessageIdentity, message.Identity);
            CollectionAssert.AreEqual(Message.CurrentVersion, message.Version);
        }
Esempio n. 6
0
        public void TestCorrelationId_IsConsistentlyTransferredViaMultipartMessage()
        {
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            var correlationId = Guid.NewGuid().ToByteArray();
            message.SetCorrelationId(correlationId);

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            CollectionAssert.AreEqual(correlationId, message.CorrelationId);
        }
Esempio n. 7
0
        public void TestMessageTTL_IsConsistentlyTransferredViaMultipartMessage()
        {
            var random = new Random((int)(0x0000ffff & DateTime.UtcNow.Ticks));
            var ttl = TimeSpan.FromSeconds(random.Next(2, 60));
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            message.TTL = ttl;

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            Assert.AreEqual(ttl, message.TTL);
        }
Esempio n. 8
0
        public void TestMessageTraceOptions_IsConsistentlyTransferredViaMultipartMessage(MessageTraceOptions routeOptions)
        {
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            message.TraceOptions = routeOptions;

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            Assert.AreEqual(routeOptions, message.TraceOptions);
        }
Esempio n. 9
0
        public void TestMessageDistribution_IsConsistentlyTransferredViaMultipartMessage()
        {
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            var distribution = message.Distribution;

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            Assert.AreEqual(distribution, message.Distribution);
        }
Esempio n. 10
0
        public void TestIfCallbackIdentityIsEqualToMessageIdentity_ReceiverIdentityIsSetToCallbackReceiverIdentity()
        {
            var message = (Message) Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);

            var callbackReceiverIdentity = Guid.NewGuid().ToByteArray();
            var callbackIdentity = SimpleMessage.MessageIdentity;
            message.RegisterCallbackPoint(callbackIdentity, callbackReceiverIdentity);

            var multipart = new MultipartMessage(message);
            message = new Message(multipart);

            CollectionAssert.AreEqual(callbackIdentity, message.CallbackIdentity);
            CollectionAssert.AreEqual(callbackReceiverIdentity, message.CallbackReceiverIdentity);
            CollectionAssert.AreEqual(callbackReceiverIdentity, message.ReceiverIdentity);
        }