コード例 #1
0
        public IPromise Send(IMessage message)
        {
            AssertMessageIsNotBroadcast(message);

            message.As <Message>().SetDomain(securityProvider.GetDomain(message.Identity));

            return(InternalEnqueueRequest(message, CallbackPoint.Create <ReceiptConfirmationMessage>()));
        }
コード例 #2
0
        private IPromise InternalEnqueueRequest(IMessage message, CallbackPoint callbackPoint)
        {
            var promise = new Promise(Interlocked.Increment(ref lastCallbackKey));

            registrationsQueue.Add(new CallbackRegistration
            {
                Message       = message,
                Promise       = promise,
                CallbackPoint = callbackPoint
            });

            return(promise);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: gitter-badger/kino
        private static void Main(string[] args)
        {
            var builder = new ContainerBuilder();
            builder.RegisterModule(new MainModule());
            var container = builder.Build();

            var messageRouter = container.Resolve<IMessageRouter>();
            messageRouter.Start();
            // Needed to let router bind to socket over INPROC. To be fixed by NetMQ in future.
            Thread.Sleep(TimeSpan.FromMilliseconds(30));

            var ccMon = container.Resolve<IClusterMonitor>();
            ccMon.Start();
            var messageHub = container.Resolve<IMessageHub>();
            messageHub.Start();

            Thread.Sleep(TimeSpan.FromSeconds(5));
            WriteLine($"Client is running... {DateTime.Now}");

            var request = Message.CreateFlowStartMessage(new HelloMessage {Greeting = Guid.NewGuid().ToString()}, HelloMessage.MessageIdentity);
            request.TraceOptions = MessageTraceOptions.None;
            var callbackPoint = new CallbackPoint(GroupCharsResponseMessage.MessageIdentity);
            var promise = messageHub.EnqueueRequest(request, callbackPoint);
            var timeout = TimeSpan.FromSeconds(4);
            if (promise.GetResponse().Wait(timeout))
            {
                var response = promise.GetResponse().Result.GetPayload<GroupCharsResponseMessage>();

                WriteLine($"Text: {response.Text}");
                foreach (var groupInfo in response.Groups)
                {
                    WriteLine($"Char: {groupInfo.Char} - {groupInfo.Count} times");
                }
            }
            else
            {
                WriteLine($"Call timed out after {timeout.TotalSeconds} sec.");
            }

            ReadLine();
            messageHub.Stop();
            messageRouter.Stop();
            ccMon.Stop();
            container.Dispose();

            WriteLine("Client stopped.");
        }
コード例 #4
0
        public IPromise EnqueueRequest(IMessage message, CallbackPoint callbackPoint)
        {
            message.As <Message>().SetDomain(securityProvider.GetDomain(message.Identity));

            return(InternalEnqueueRequest(message, callbackPoint));
        }
コード例 #5
0
ファイル: MessagHubTests.cs プロジェクト: gitter-badger/kino
        public void TestEnqueueRequest_RegistersMessageAndExceptionHandlers()
        {
            var messageHub = new MessageHub(socketFactory.Object,
                                            callbackHandlerStack.Object,
                                            config,
                                            messageTracer.Object,
                                            logger);
            try
            {
                messageHub.Start();

                var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
                var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

                messageHub.EnqueueRequest(message, callback);

                Thread.Sleep(AsyncOp);

                callbackHandlerStack.Verify(m => m.Push(It.Is<CorrelationId>(c => Unsafe.Equals(c.Value, message.CorrelationId)),
                                                        It.IsAny<IPromise>(),
                                                        It.Is<IEnumerable<MessageIdentifier>>(en => ContainsMessageAndExceptionRegistrations(en))),
                                            Times.Once);
            }
            finally
            {
                messageHub.Stop();
            }
        }
コード例 #6
0
ファイル: MessagHubTests.cs プロジェクト: gitter-badger/kino
        public void TestWhenMessageReceivedAndNoHandlerRegistered_PromiseIsNotResolved()
        {
            var messageHub = new MessageHub(socketFactory.Object,
                                            callbackHandlerStack.Object,
                                            config,
                                            messageTracer.Object,
                                            logger);
            try
            {
                messageHub.Start();

                var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
                var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

                var promise = messageHub.EnqueueRequest(message, callback);
                callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns((IPromise) null);
                messageHubSocketFactory.GetReceivingSocket().DeliverMessage(message);

                Thread.Sleep(AsyncOpCompletionDelay);

                Assert.IsFalse(promise.GetResponse().Wait(AsyncOpCompletionDelay));
            }
            finally
            {
                messageHub.Stop();
            }
        }
コード例 #7
0
ファイル: MessagHubTests.cs プロジェクト: gitter-badger/kino
        public void TestWhenExceptionMessageReceived_PromiseThrowsException()
        {
            var messageHub = new MessageHub(socketFactory.Object,
                                            callbackHandlerStack.Object,
                                            config,
                                            messageTracer.Object,
                                            logger);
            try
            {
                messageHub.Start();

                var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
                var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

                var promise = messageHub.EnqueueRequest(message, callback);
                callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns(promise);
                var errorMessage = Guid.NewGuid().ToString();
                var exception = Message.Create(new ExceptionMessage {Exception = new Exception(errorMessage)}, ExceptionMessage.MessageIdentity);
                messageHubSocketFactory.GetReceivingSocket().DeliverMessage(exception);

                Assert.Throws<AggregateException>(() => { var response = promise.GetResponse().Result; }, errorMessage);
                Assert.DoesNotThrow(() => { var response = promise.GetResponse(); });
            }
            finally
            {
                messageHub.Stop();
            }
        }
コード例 #8
0
ファイル: MessagHubTests.cs プロジェクト: gitter-badger/kino
        public void TestWhenMessageReceived_CorrespondingPromiseResultSet()
        {
            var messageHub = new MessageHub(socketFactory.Object,
                                            callbackHandlerStack.Object,
                                            config,
                                            messageTracer.Object,
                                            logger);
            try
            {
                messageHub.Start();

                var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
                var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

                var promise = messageHub.EnqueueRequest(message, callback);
                callbackHandlerStack.Setup(m => m.Pop(It.IsAny<CallbackHandlerKey>())).Returns(promise);
                messageHubSocketFactory.GetReceivingSocket().DeliverMessage(message);

                var response = promise.GetResponse().Result;

                Assert.IsNotNull(response);
                Assert.AreEqual(message, response);
            }
            finally
            {
                messageHub.Stop();
            }
        }
コード例 #9
0
ファイル: MessagHubTests.cs プロジェクト: gitter-badger/kino
        public void TestEnqueueRequest_SendsMessageWithCallbackReceiverIdentityEqualsToReceivingSocketIdentity()
        {
            var messageHub = new MessageHub(socketFactory.Object,
                                            callbackHandlerStack.Object,
                                            config,
                                            messageTracer.Object,
                                            logger);
            try
            {
                messageHub.Start();

                var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
                var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

                messageHub.EnqueueRequest(message, callback);

                Thread.Sleep(AsyncOp);

                var messageOut = messageHubSocketFactory.GetSendingSocket().GetSentMessages().Last();
                var receivingSocket = messageHubSocketFactory.GetReceivingSocket();

                Assert.IsNotNull(messageOut);
                CollectionAssert.AreEqual(receivingSocket.GetIdentity(), messageOut.CallbackReceiverIdentity);
                CollectionAssert.AreEqual(callback.MessageIdentity, messageOut.CallbackIdentity);
            }
            finally
            {
                messageHub.Stop();
            }
        }
コード例 #10
0
        private static IMessage SendMessageOverMessageHub()
        {
            var messageTracer = new Mock<kino.Client.IMessageTracer>();
            var logger = new Mock<ILogger>();
            var sockrtFactory = new Mock<ISocketFactory>();
            var socket = new StubSocket();
            sockrtFactory.Setup(m => m.CreateDealerSocket()).Returns(socket);

            var message = Message.CreateFlowStartMessage(new SimpleMessage(), SimpleMessage.MessageIdentity);
            var callback = new CallbackPoint(SimpleMessage.MessageIdentity);

            var messageHub = new MessageHub(sockrtFactory.Object,
                                            new CallbackHandlerStack(new ExpirableItemCollection<CorrelationId>(logger.Object)),
                                            new MessageHubConfiguration(),
                                            messageTracer.Object,
                                            logger.Object);
            messageHub.Start();
            messageHub.EnqueueRequest(message, callback);
            Thread.Sleep(AsyncOpCompletionDelay);

            return socket.GetSentMessages().BlockingLast(AsyncOpCompletionDelay);
        }