当前位置: 首页>>代码示例>>C#>>正文


C# FutureMessage.Set方法代码示例

本文整理汇总了C#中FutureMessage.Set方法的典型用法代码示例。如果您正苦于以下问题:C# FutureMessage.Set方法的具体用法?C# FutureMessage.Set怎么用?C# FutureMessage.Set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FutureMessage的用法示例。


在下文中一共展示了FutureMessage.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Should_support_the_asynchronous_programming_model

		public void Should_support_the_asynchronous_programming_model()
		{
			var pongReceived = new FutureMessage<PongMessage>();
			var pingReceived = new FutureMessage<PingMessage>();
			var callbackCalled = new FutureMessage<IAsyncResult>();

			RemoteBus.SubscribeHandler<PingMessage>(x =>
				{
					pingReceived.Set(x);
					RemoteBus.MessageContext<PingMessage>().Respond(new PongMessage(x.CorrelationId));
				});

			var ping = new PingMessage();

			var timeout = 8.Seconds();

			LocalBus.BeginPublishRequest(ping, callbackCalled.Set, null, x =>
				{
					x.Handle<PongMessage>(message =>
						{
							message.CorrelationId.ShouldEqual(ping.CorrelationId, "The response correlationId did not match");
							pongReceived.Set(message);
						});

					x.SetTimeout(timeout);
				});

			callbackCalled.IsAvailable(timeout).ShouldBeTrue("The callback was not called");

			LocalBus.EndRequest(callbackCalled.Message);

			pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
			pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
		}
开发者ID:jimitndiaye,项目名称:MassTransit,代码行数:34,代码来源:PublishRequest_Specs.cs

示例2: A_clean_method_of_a_request_reply_should_be_possible

		public void A_clean_method_of_a_request_reply_should_be_possible()
		{
			var ponged = new FutureMessage<PongMessage>();

			RemoteBus.SubscribeHandler<PingMessage>(x =>
				{
					// timing issue here it seems, but that's what Respond() is for, to RESPOND to messages
					// and not publish responses
					RemoteBus.ShouldHaveSubscriptionFor<PongMessage>();

					RemoteBus.Publish(new PongMessage(x.CorrelationId));
				});

			LocalBus.ShouldHaveSubscriptionFor<PingMessage>();

			var ping = new PingMessage();


			LocalBus.PublishRequest(ping, x =>
				{
					x.Handle<PongMessage>(message =>
						{
							message.CorrelationId.ShouldEqual(ping.CorrelationId);
							ponged.Set(message);
						});

					x.HandleTimeout(8.Seconds(), () => { });
				});

			ponged.IsAvailable(8.Seconds()).ShouldBeTrue("No ping response received");
		}
开发者ID:ahjohannessen,项目名称:MassTransit,代码行数:31,代码来源:RequestResponseScope_Specs.cs

示例3: A_response_should_be_published_if_no_reply_address_is_specified

		public void A_response_should_be_published_if_no_reply_address_is_specified()
		{
			PingMessage ping = new PingMessage();

			TestMessageConsumer<PongMessage> otherConsumer = new TestMessageConsumer<PongMessage>();
			RemoteBus.Subscribe(otherConsumer);

			TestCorrelatedConsumer<PongMessage, Guid> consumer = new TestCorrelatedConsumer<PongMessage, Guid>(ping.CorrelationId);
			LocalBus.Subscribe(consumer);

			FutureMessage<PongMessage> pong = new FutureMessage<PongMessage>();

			RemoteBus.Subscribe<PingMessage>(message =>
				{
					pong.Set(new PongMessage(message.CorrelationId));

					CurrentMessage.Respond(pong.Message);
				});

			LocalBus.Publish(ping);

			Assert.IsTrue(pong.IsAvailable(3.Seconds()), "No pong generated");

			consumer.ShouldHaveReceivedMessage(pong.Message, 3.Seconds());
			otherConsumer.ShouldHaveReceivedMessage(pong.Message, 1.Seconds());
		}
开发者ID:hakeemsm,项目名称:MassTransit,代码行数:26,代码来源:MessageContext_Specs.cs

示例4: Should_ignore_a_response_that_was_not_for_us

        public void Should_ignore_a_response_that_was_not_for_us()
        {
            var pongReceived = new FutureMessage<PongMessage>();
            var pingReceived = new FutureMessage<PingMessage>();
            var badResponse = new FutureMessage<PongMessage>();

            LocalBus.SubscribeHandler<PongMessage>(pongReceived.Set);

            RemoteBus.SubscribeContextHandler<PingMessage>(x =>
                {
                    pingReceived.Set(x.Message);
                    RemoteBus.Publish(new PongMessage {TransactionId = x.Message.TransactionId});
                });
            LocalBus.ShouldHaveSubscriptionFor<PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 8.Seconds();

            Assert.Throws<RequestTimeoutException>(() =>
                {
                    RemoteBus.Endpoint.SendRequest(ping, LocalBus, x =>
                        {
                            x.Handle<PongMessage>(badResponse.Set);

                            x.SetTimeout(timeout);
                        });
                });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
            badResponse.IsAvailable(2.Seconds()).ShouldBeFalse("Should not have received a response");
        }
开发者ID:andreialecu,项目名称:MassTransit,代码行数:33,代码来源:PublishRequest_Specs.cs

示例5: The_retry_count_should_be_set_on_the_message

		public void The_retry_count_should_be_set_on_the_message()
		{
			FutureMessage<PingMessage> future = new FutureMessage<PingMessage>();

			bool first = true;

			LocalBus.Subscribe<PingMessage>(message =>
				{
					if(first)
					{
						Assert.AreEqual(0, CurrentMessage.Headers.RetryCount);

						CurrentMessage.RetryLater();

						first = false;
					}
					else
					{
						Assert.AreEqual(1, CurrentMessage.Headers.RetryCount);

						future.Set(message);
					}
				});

			LocalBus.Publish(new PingMessage());

			Assert.IsTrue(future.IsAvailable(5.Seconds()));
		}
开发者ID:KevM,项目名称:MassTransit,代码行数:28,代码来源:Retry_Specs.cs

示例6: Should_use_a_clean_syntax_following_standard_conventions

		public void Should_use_a_clean_syntax_following_standard_conventions()
		{
			var pongReceived = new FutureMessage<PongMessage>();
			var pingReceived = new FutureMessage<PingMessage>();

			RemoteBus.SubscribeHandler<PingMessage>(x =>
				{
					pingReceived.Set(x);
					RemoteBus.MessageContext<PingMessage>().Respond(new PongMessage(x.CorrelationId));
				});

			var ping = new PingMessage();

			var timeout = 8.Seconds();

			LocalBus.PublishRequest(ping, x =>
				{
					x.Handle<PongMessage>(message =>
						{
							message.CorrelationId.ShouldEqual(ping.CorrelationId, "The response correlationId did not match");
							pongReceived.Set(message);
						});

					x.SetTimeout(timeout);
				});

			pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
			pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
		}
开发者ID:jimitndiaye,项目名称:MassTransit,代码行数:29,代码来源:PublishRequest_Specs.cs

示例7: A_response_should_be_published_if_no_reply_address_is_specified

		public void A_response_should_be_published_if_no_reply_address_is_specified()
		{
			var ping = new PingMessage();

			var otherConsumer = new TestMessageConsumer<PongMessage>();
			RemoteBus.SubscribeInstance(otherConsumer);

			var consumer = new TestCorrelatedConsumer<PongMessage, Guid>(ping.CorrelationId);
			LocalBus.SubscribeInstance(consumer);

			var pong = new FutureMessage<PongMessage>();

			RemoteBus.SubscribeHandler<PingMessage>(message =>
				{
					pong.Set(new PongMessage(message.CorrelationId));

					RemoteBus.Context().Respond(pong.Message);
				});

			LocalBus.Publish(ping);

			pong.IsAvailable(8.Seconds()).ShouldBeTrue("No pong generated");

			consumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
			otherConsumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
		}
开发者ID:jimitndiaye,项目名称:MassTransit,代码行数:26,代码来源:MessageContext_Specs.cs

示例8: The_retry_count_should_be_set_on_the_message

		public void The_retry_count_should_be_set_on_the_message()
		{
			var future = new FutureMessage<PingMessage>();

			bool first = true;

			LocalBus.SubscribeHandler<PingMessage>(message =>
				{
					if (first)
					{
						Assert.AreEqual(0, LocalBus.Context().RetryCount);

						LocalBus.MessageContext<PingMessage>().RetryLater();

						first = false;
					}
					else
					{
						Assert.AreEqual(1, LocalBus.Context().RetryCount);

						future.Set(message);
					}
				});

			LocalBus.ShouldHaveRemoteSubscriptionFor<PingMessage>();

			LocalBus.Publish(new PingMessage());

			Assert.IsTrue(future.IsAvailable(20.Seconds()));
		}
开发者ID:cstick,项目名称:MassTransit,代码行数:30,代码来源:Retry_Specs.cs

示例9: EstablishContext

		protected override void EstablishContext()
		{
			base.EstablishContext();

			_ping = new PingMessage();
			_future = new FutureMessage<PingMessage, Guid>(_ping.CorrelationId);

			_unsubscribe = RemoteBus.SubscribeHandler<PingMessage>(message => { _future.Set(message); });


			RemoteBus.ShouldHaveRemoteSubscriptionFor<PingMessage>();

			//LocalBus.ShouldHaveRemoteSubscriptionFor<PingMessage>();

			Trace.WriteLine("LocalBus");

			LocalBus.OutboundPipeline.Trace();

			Trace.WriteLine("RemoteBus");

			RemoteBus.OutboundPipeline.Trace();


			LocalBus.Publish(_ping);
		}
开发者ID:LucidSage,项目名称:MassTransit,代码行数:25,代码来源:Group_distributor_with_control_bus_should_work.cs

示例10: A_response_should_be_sent_directly_if_a_reply_address_is_specified

        public void A_response_should_be_sent_directly_if_a_reply_address_is_specified()
        {
            var ping = new PingMessage();

            var otherConsumer = new TestMessageConsumer<PongMessage>();
            RemoteBus.SubscribeInstance(otherConsumer);

            var consumer = new TestCorrelatedConsumer<PongMessage, Guid>(ping.CorrelationId);
            LocalBus.SubscribeInstance(consumer);

            var pong = new FutureMessage<PongMessage>();

            RemoteBus.SubscribeHandler<PingMessage>(message =>
                {
                    pong.Set(new PongMessage(message.CorrelationId));

                    RemoteBus.Context().Respond(pong.Message);
                });

            RemoteBus.ShouldHaveRemoteSubscriptionFor<PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor<PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor<PingMessage>();

            LocalBus.Publish(ping, context => context.SendResponseTo(LocalBus));

            Assert.IsTrue(pong.IsAvailable(8.Seconds()), "No pong generated");

            consumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
            otherConsumer.ShouldNotHaveReceivedMessage(pong.Message, 1.Seconds());
        }
开发者ID:cstick,项目名称:MassTransit,代码行数:30,代码来源:MessageContext_Specs.cs

示例11: Should_support_send_as_well

        public void Should_support_send_as_well()
        {
            var pongReceived = new FutureMessage<PongMessage>();
            var pingReceived = new FutureMessage<PingMessage>();

            RemoteBus.SubscribeContextHandler<PingMessage>(x =>
                {
                    pingReceived.Set(x.Message);
                    x.Respond(new PongMessage {TransactionId = x.Message.TransactionId});
                });
            LocalBus.ShouldHaveSubscriptionFor<PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 8.Seconds();

            RemoteBus.Endpoint.SendRequest(ping, LocalBus, x =>
                {
                    x.Handle<PongMessage>(message =>
                        {
                            message.TransactionId.ShouldEqual(ping.TransactionId,
                                "The response correlationId did not match");
                            pongReceived.Set(message);
                        });

                    x.SetTimeout(timeout);
                });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
        }
开发者ID:andreialecu,项目名称:MassTransit,代码行数:31,代码来源:PublishRequest_Specs.cs

示例12: EstablishContext

		protected override void EstablishContext()
		{
			base.EstablishContext();

			_future = new FutureMessage<PingMessage>();

			LocalBus.Subscribe<PingMessage>(message => _future.Set(message));

			_ping = new PingMessage();

			LocalBus.Publish(_ping);
		}
开发者ID:KevM,项目名称:MassTransit,代码行数:12,代码来源:Transactional_Specs.cs

示例13: Subscring_to_an_endpoint_should_accept_and_dispatch_messages

		public void Subscring_to_an_endpoint_should_accept_and_dispatch_messages()
		{
            FutureMessage<PingMessage> fm=new FutureMessage<PingMessage>();
			bool workDid = false;

			LocalBus.Subscribe<PingMessage>(
				(msg)=> {workDid = true; fm.Set(msg); },
				delegate { return true; });

			RemoteBus.Publish(_message);
		    fm.IsAvailable(1.Seconds());
			Assert.That(workDid, Is.True, "Lazy Test!");
		}
开发者ID:KevM,项目名称:MassTransit,代码行数:13,代码来源:MessageQueueEndpoint_MeetsCriteria.cs

示例14: EstablishContext

		protected override void EstablishContext()
		{
			base.EstablishContext();

			_ping = new PingMessage();

			_future = new FutureMessage<PingMessage, Guid>(_ping.CorrelationId);

			RemoteBus.SubscribeHandler<PingMessage>(message => { _future.Set(message); });

			LocalBus.ShouldHaveRemoteSubscriptionFor<PingMessage>();

			LocalBus.Publish(_ping);
		}
开发者ID:codeyu,项目名称:MassTransit,代码行数:14,代码来源:Multicast_subscription_client_should_work.cs

示例15: Should_request_an_instance_of_the_consumer_for_each_message

		public void Should_request_an_instance_of_the_consumer_for_each_message()
		{
			var called = new FutureMessage<PingMessage>();

			var ping = new PingMessage();

			var getter = MockRepository.GenerateMock<HandlerSelector<PingMessage>>();
			getter.Expect(x => x(null)).IgnoreArguments().Return(x => called.Set(x.Message));

			LocalBus.SubscribeHandlerSelector(getter);

			LocalBus.Publish(ping);

			called.IsAvailable(3.Seconds()).ShouldBeTrue();
		}
开发者ID:cstick,项目名称:MassTransit,代码行数:15,代码来源:SubscribeConsumer_Specs.cs


注:本文中的FutureMessage.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。