本文整理汇总了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");
}
示例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");
}
示例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());
}
示例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");
}
示例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()));
}
示例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");
}
示例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());
}
示例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()));
}
示例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);
}
示例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());
}
示例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");
}
示例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);
}
示例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!");
}
示例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);
}
示例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();
}