本文整理汇总了C#中MessageBus类的典型用法代码示例。如果您正苦于以下问题:C# MessageBus类的具体用法?C# MessageBus怎么用?C# MessageBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageBus类属于命名空间,在下文中一共展示了MessageBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySubscriberIsInitializedWhenRegistered
public async Task VerifySubscriberIsInitializedWhenRegistered()
{
// Setup the message bus.
var cs = Any.String();
var subscriber = new MockSubscriber();
var mbf = new MockMessageBusFactory { Subscriber = subscriber };
var mbd = new MessageBusDescription { ConnectionString = cs, Factory = mbf };
var bus = new MessageBus(mbd);
var entity = "MessageSendSuccess;MessageSendFailure";
var name = "MessageSendSuccess";
Assert.IsFalse(
subscriber.IsInitialized,
"The subscriber should not be initialized before it is registered.");
var called = false;
// Register the subscriber.
await bus.RegisterHandlerAsync(entity, name, message => Task.Run(() => { called = true; }));
Assert.IsTrue(subscriber.IsInitialized, "The subscriber should be initialized after it is registered.");
Assert.AreEqual(subscriber.Description.ConnectionString, cs);
Assert.AreEqual(subscriber.Description.Entity, entity);
Assert.AreEqual(subscriber.Description.Name, name);
await subscriber.Handler.Invoke(null);
Assert.IsTrue(called, "The handler must be callable.");
// Close the bus.
await bus.CloseAsync();
Assert.IsTrue(subscriber.IsClosed, "The subscriber should be closed after the bus is closed.");
}
示例2: WhenSinkThrowsMessagesContinueToBeDelivered
public void WhenSinkThrowsMessagesContinueToBeDelivered()
{
var sink = Substitute.For<IMessageSink>();
var msg1 = Substitute.For<IMessageSinkMessage>();
var msg2 = Substitute.For<IMessageSinkMessage>();
var msg3 = Substitute.For<IMessageSinkMessage>();
var messages = new List<IMessageSinkMessage>();
sink.OnMessage(Arg.Any<IMessageSinkMessage>())
.Returns(callInfo =>
{
var msg = (IMessageSinkMessage)callInfo[0];
if (msg == msg2)
throw new Exception("whee!");
else
messages.Add(msg);
return false;
});
using (var bus = new MessageBus(sink))
{
bus.QueueMessage(msg1);
bus.QueueMessage(msg2);
bus.QueueMessage(msg3);
}
Assert.Collection(messages,
message => Assert.Same(message, msg1),
message => Assert.Same(message, msg3)
);
}
示例3: Main
static void Main(string[] args)
{
var bus = new MessageBus();
var input = "";
while ((input = Console.ReadLine()) != "Quit")
{
if (input == "1")
MessageBus.Bus.Publish(new CreateIdeaMessage
{
IdeaId = 1,
CaseId = 100
});
else if(input=="2")
MessageBus.Bus.Publish(new CreateObjectiveMessage
{
ObjectiveId = 12,
CaseId = 100
});
else
MessageBus.Bus.Publish(new CreateTaskMessage
{
TaskId = 12,
CaseId = 100
});
}
}
示例4: ThisAddIn_Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Trello = new Trello("1ed8d91b5af35305a60e169a321ac248");
MessageBus = new MessageBus();
var exportCardsControl = new ExportCardsControl();
var importCardsControl = new ImportCardsControl();
var authorizeForm = new AuthorizationDialog();
ExportCardsTaskPane = CustomTaskPanes.Add(exportCardsControl, "Export cards to Trello");
ExportCardsTaskPane.Width = 300;
ExportCardsTaskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
ImportCardsTaskPane = CustomTaskPanes.Add(importCardsControl, "Import cards from Trello");
ImportCardsTaskPane.Width = 300;
ImportCardsTaskPane.DockPositionRestrict = MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoHorizontal;
TaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
ExportCardsPresenter = new ExportCardsPresenter(exportCardsControl, Trello, new GridToNewCardTransformer(), TaskScheduler, MessageBus);
ImportCardsPresenter = new ImportCardsPresenter(importCardsControl, MessageBus, Trello, TaskScheduler);
AuthorizePresenter = new AuthorizePresenter(authorizeForm, Trello, MessageBus);
Globals.Ribbons.TrelloRibbon.SetMessageBus(MessageBus);
TryToAuthorizeTrello();
}
示例5: Configuration
private Configuration()
{
/* bus intialisation */
_bus = new MessageBus();
//var eventStore = new SqlServerEventStore(_bus);
//var eventStore = new SqlLiteEventStore(_bus);
var eventStore = new InMemoryEventStore(_bus, inMemDict );
var repository = new DomainRepository(eventStore);
/* Account Domain */
var commandService = new AccountApplicationService(repository);
_bus.RegisterHandler<RegisterAccountCommand>(commandService.Handle);
_bus.RegisterHandler<DebitAccountCommand>(commandService.Handle);
_bus.RegisterHandler<UnlockAccountCommand>(commandService.Handle);
var infoProjection = new AccountInfoProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(infoProjection.Handle);
_bus.RegisterHandler<AccountLockedEvent>(infoProjection.Handle);
_bus.RegisterHandler<AccountUnlockedEvent>(infoProjection.Handle);
var balanceProjection = new AccountBalanceProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(balanceProjection.Handle);
_bus.RegisterHandler<AccountDebitedEvent>(balanceProjection.Handle);
var notification = new NotificationProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(notification.Handle);
_bus.RegisterHandler<AccountDebitedEvent>(notification.Handle);
_bus.RegisterHandler<AccountLockedEvent>(notification.Handle);
_bus.RegisterHandler<AccountUnlockedEvent>(notification.Handle);
_bus.RegisterHandler<AccountOverdrawAttemptedEvent>(notification.Handle);
_AccountReadModel = new AccountReadModelFacade(balanceProjection, infoProjection, notification);
/* News Domain*/
//var newsEventStore = new SqlServerEventStore(_bus);
//var newsEventStore = new SqlLiteEventStore(_bus);
var newsEventStore = new InMemoryEventStore(_bus, inMemDict);
var newsRepository = new DomainRepository(eventStore);
/* Register command on the News bounded context */
var newsCommandService = new AccountManager.Models.News.Domain.NewsApplicationService(newsRepository);
_bus.RegisterHandler<AccountManager.Models.News.Commands.CreateNewsCommand>(newsCommandService.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Commands.PublishNewsCommand>(newsCommandService.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Commands.UnpublishNewsCommand>(newsCommandService.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Commands.UpdateNewsCommand>(newsCommandService.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Commands.DeleteNewsCommand>(newsCommandService.Handle);
var _newsProjection = new AccountManager.Models.News.ReadModel.NewsProjection();
_bus.RegisterHandler<AccountManager.Models.News.Events.NewsCreatedEvent>(_newsProjection.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Events.NewsPublishedEvent>(_newsProjection.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Events.NewsUnpublishedEvent>(_newsProjection.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Events.NewsUpdatedEvent>(_newsProjection.Handle);
_bus.RegisterHandler<AccountManager.Models.News.Events.NewsDeletedEvent>(_newsProjection.Handle);
_NewsReadModel = new NewsReadModelFacade(_newsProjection);
/* rehydrate */
var events = eventStore.GetAllEventsEver();
_bus.Publish(events);
}
示例6: Configuration
private Configuration()
{
_bus = new MessageBus();
var eventStore = new SqlEventStore(_bus);
var repository = new DomainRepository(eventStore);
var commandService = new AccountApplicationService(repository);
_bus.RegisterHandler<RegisterAccountCommand>(commandService.Handle);
_bus.RegisterHandler<DebitAccountCommand>(commandService.Handle);
_bus.RegisterHandler<UnlockAccountCommand>(commandService.Handle);
var infoProjection = new AccountInfoProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(infoProjection.Handle);
_bus.RegisterHandler<AccountLockedEvent>(infoProjection.Handle);
_bus.RegisterHandler<AccountUnlockedEvent>(infoProjection.Handle);
var balanceProjection = new AccountBalanceProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(balanceProjection.Handle);
_bus.RegisterHandler<AccountDebitedEvent>(balanceProjection.Handle);
var notification = new NotificationProjection();
_bus.RegisterHandler<AccountRegisteredEvent>(notification.Handle);
_bus.RegisterHandler<AccountDebitedEvent>(notification.Handle);
_bus.RegisterHandler<AccountLockedEvent>(notification.Handle);
_bus.RegisterHandler<AccountUnlockedEvent>(notification.Handle);
_bus.RegisterHandler<OverdrawAttemptedEvent>(notification.Handle);
_readModel = new ReadModelFacade(balanceProjection, infoProjection, notification);
var events = eventStore.GetAllEventsEver();
_bus.Publish(events);
}
示例7: Handle
/// <summary>
/// Handles the specified subscription command line options.
/// </summary>
/// <param name="options">
/// The options.
/// </param>
public static void Handle(SubscriptionOptions options)
{
if (options.IsVerbose)
{
Debug.Listeners.Add(new ColoredConsoleTraceListener());
}
OutputWriter = !string.IsNullOrWhiteSpace(options.OutputFileName)
? new StreamWriter(options.OutputFileName)
: Console.Out;
var description = new MessageBusDescription
{
ConnectionString = options.ConnectionString,
Factory =
DependencyResolver.Resolve<IMessageBusFactory>(
options.Factory),
StorageConnectionString = options.StorageConnectionString
};
var bus = new MessageBus(description);
bus.RegisterHandlerAsync(options.Entity, options.Name, OnMessageArrived).Wait();
Debug.Print("This is a debug print.");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Console.WriteLine("Closing message bus...");
bus.CloseAsync().ContinueWith(t => Console.WriteLine("Message bus is closed.")).Wait();
}
示例8: SkyBox
public SkyBox(int id, MessageBus bus)
{
Id = id;
Bus = bus;
Position = new Vect3(0, 0, 0);
Rotation = new Quat(Math.Sqrt(0.5), 0, 0, Math.Sqrt(0.5));
}
示例9: MultiplePublishers
public void MultiplePublishers()
{
const string message1 = "Test Message #1";
const string message2 = "Test Message #2";
const string message3 = "Test Message #3";
const string message4 = "Test Message #4";
string receivedMessage = null;
var messageBus = new MessageBus();
var publisher1 = new Subject<string>();
var publisher2 = new Subject<string>();
var subscription1 = messageBus.RegisterPublisher(publisher1);
messageBus.RegisterPublisher(publisher2);
messageBus.Listen<string>().Subscribe(m => receivedMessage = m, e => Assert.Fail(), Assert.Fail);
Assert.IsNull(receivedMessage);
messageBus.Publish(message1);
Assert.AreEqual(message1, receivedMessage);
publisher1.OnNext(message2);
Assert.AreEqual(message2, receivedMessage);
publisher2.OnNext(message3);
Assert.AreEqual(message3, receivedMessage);
subscription1.Dispose();
publisher1.OnNext(message4);
Assert.AreEqual(message3, receivedMessage);
publisher2.OnNext(message4);
Assert.AreEqual(message4, receivedMessage);
}
示例10: CreateBus
public void CreateBus()
{
m_Sender = Substitute.For<IMessageSender>();
m_Receiver = Substitute.For<IMessageReceiver>();
m_Bus = new MessageBus(m_Sender,
m_Receiver);
}
示例11: Bootstrapper
/// <summary>
/// Construct a boot strapper for Light framework.
/// </summary>
/// <param name="Args">Application init args</param>
public Bootstrapper(string[] Args)
{
MessageBus = new MessageBus();
Modules = new List<LightModule>();
LoadAssemblies();
MessageBus.Run();
}
示例12: FalseWithNoSubscribers
public void FalseWithNoSubscribers()
{
var bus = new MessageBus();
bus.HasSubscriberFor<Message>()
.Should().BeFalse(
"no subscribers have been added");
}
示例13: Initialise
public void Initialise(MessageBus bus)
{
Bus = bus;
SystemMessages = Bus.OfType<SystemMessage>().AsObservable();
ObjectLifeTimeRequests = Bus.OfType<IObjectLifetimeRequest>().AsObservable();
ObjectLifeTimeNotifications = Bus.OfType<IObjectLifetimeNotification>().AsObservable();
}
示例14: GetPersistedEventBus
private static MessageBus GetPersistedEventBus()
{
var persistedEventBus = new MessageBus();
//application handlers
persistedEventBus.RegisterHandler<RepliedToPostEvent>(MessageHandlerType.Synchronous, OnRepliedToPost, true);
persistedEventBus.RegisterHandler<ApprovedCommentEvent>(MessageHandlerType.Synchronous, OnApprovedComment, true);
persistedEventBus.RegisterHandler<FailedMessage>(MessageHandlerType.Synchronous, OnFailMessage, false);
//sync handlers
//persistedEventBus.RegisterHandler<RepliedToPostEvent>(MessageHandlerType.Synchronous, e => UpdateComment( e.Comment), true);
//persistedEventBus.RegisterHandler<ApprovedCommentEvent>(MessageHandlerType.Synchronous, e => UpdateComment( e.Comment), true);
//persistedEventBus.RegisterHandler<AssignedCategoryToPostEvent>(MessageHandlerType.Synchronous, e => CreateCategoryLink(e.Post,e.Category), true);
//persistedEventBus.RegisterHandler<EditedPostEvent>(MessageHandlerType.Synchronous, e => UpdatePost(e.Post), true);
//persistedEventBus.RegisterHandler<EnabledCommentsEvent>(MessageHandlerType.Synchronous, e => UpdatePost(e.Post), true);
//persistedEventBus.RegisterHandler<DisabledCommentsEvent>(MessageHandlerType.Synchronous, e => UpdatePost(e.Post), true);
//persistedEventBus.RegisterHandler<PostCreatedEvent>(MessageHandlerType.Synchronous, e => UpdatePost(e.Post), true);
//persistedEventBus.RegisterHandler<PublishedPostEvent>(MessageHandlerType.Synchronous, e => DeletePost(e.Post), true);
//persistedEventBus.RegisterHandler<UnpublishedPostEvent>(MessageHandlerType.Synchronous, e => DeletePost(e.Post), true);
//persistedEventBus.RegisterHandler<PostDeletedEvent>(MessageHandlerType.Synchronous, e => DeletePost(e.Post), true);
return persistedEventBus;
}
示例15: CanListenPositionChangeEvents
public void CanListenPositionChangeEvents()
{
// ARRANGE
var waitEvent = new ManualResetEvent(false);
var messageBus = new MessageBus();
NmeaPositionMocker mocker;
int count = 0;
messageBus.AsObservable<GeoPosition>()
.ObserveOn(Scheduler.ThreadPool)
.Subscribe(position => count++);
// ACT
Action<TimeSpan> delayAction = _ => Thread.Sleep(0); // do not wait to make test faster
using (Stream stream = new FileStream(TestHelper.NmeaFilePath, FileMode.Open))
{
mocker = new NmeaPositionMocker(stream, messageBus);
mocker.OnDone += (s, e) => waitEvent.Set();
mocker.Start(delayAction);
}
// ASSERT
if(!waitEvent.WaitOne(TimeSpan.FromSeconds(60)))
throw new TimeoutException();
mocker.Stop();
Assert.AreEqual(16, count);
}