本文整理汇总了C#中MessageBus类的典型用法代码示例。如果您正苦于以下问题:C# MessageBus类的具体用法?C# MessageBus怎么用?C# MessageBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageBus类属于命名空间,在下文中一共展示了MessageBus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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.");
}
开发者ID:blinds52,项目名称:Microsoft-Message-Bridge,代码行数:33,代码来源:MessageBusFixture.cs
示例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)
);
}
开发者ID:ansarisamer,项目名称:xunit,代码行数:31,代码来源:MessageBusTests.cs
示例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
});
}
}
开发者ID:AOlefirenko,项目名称:rabbitMq_example,代码行数:26,代码来源:Program.cs
示例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();
}
开发者ID:bdwakefield,项目名称:TrelloExcel,代码行数:27,代码来源:ThisAddIn.cs
示例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);
}
开发者ID:rlasjunies,项目名称:CQRS_trial,代码行数:60,代码来源:Configuration.cs
示例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);
}
开发者ID:barissonmez,项目名称:aspConf-cqrs,代码行数:32,代码来源:Configuration.cs
示例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();
}
开发者ID:blinds52,项目名称:Microsoft-Message-Bridge,代码行数:35,代码来源:SubscriptionHandler.cs
示例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));
}
开发者ID:veggielane,项目名称:ORTS,代码行数:7,代码来源:SkyBox.cs
示例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);
}
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:33,代码来源:MessageBusTest.cs
示例10: CreateBus
public void CreateBus()
{
m_Sender = Substitute.For<IMessageSender>();
m_Receiver = Substitute.For<IMessageReceiver>();
m_Bus = new MessageBus(m_Sender,
m_Receiver);
}
开发者ID:jystic,项目名称:Triangles-in-space,代码行数:7,代码来源:MessageBusTests.cs
示例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();
}
开发者ID:pandorla1984,项目名称:Light,代码行数:11,代码来源:Bootstrapper.cs
示例12: FalseWithNoSubscribers
public void FalseWithNoSubscribers()
{
var bus = new MessageBus();
bus.HasSubscriberFor<Message>()
.Should().BeFalse(
"no subscribers have been added");
}
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:7,代码来源:MessageBusHasSubscribersTest.cs
示例13: Initialise
public void Initialise(MessageBus bus)
{
Bus = bus;
SystemMessages = Bus.OfType<SystemMessage>().AsObservable();
ObjectLifeTimeRequests = Bus.OfType<IObjectLifetimeRequest>().AsObservable();
ObjectLifeTimeNotifications = Bus.OfType<IObjectLifetimeNotification>().AsObservable();
}
开发者ID:veggielane,项目名称:orts_old,代码行数:7,代码来源:BusFilters.cs
示例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;
}
开发者ID:attila3453,项目名称:alsing,代码行数:28,代码来源:Config.cs
示例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);
}
开发者ID:RagnarDanneskjold,项目名称:utymap,代码行数:26,代码来源:NmeaPositionMockerTests.cs
示例16: Can_send_and_receive_async_message
public void Can_send_and_receive_async_message()
{
var trigger = new AutoResetEvent(false);
IMessageBus bus = new MessageBus();
TestMessage receivedMessage = null;
int currentThreadId = Thread.CurrentThread.ManagedThreadId;
int handlerThreadId = 0;
bus.RegisterHandler<TestMessage>(MessageHandlerType.Asynchronous, message =>
{
handlerThreadId = Thread.CurrentThread.ManagedThreadId;
receivedMessage = message;
trigger.Set();
}, false);
var sentMessage = new TestMessage
{
Text = "Hello bus"
};
bus.Send(sentMessage);
trigger.WaitOne(1000);
//ensure we got the message
Assert.AreSame(sentMessage, receivedMessage);
//ensure we didn't handle it in the main thread
Assert.AreNotEqual(currentThreadId, handlerThreadId);
}
开发者ID:attila3453,项目名称:alsing,代码行数:28,代码来源:Alsing.Messaging.Tests.cs
示例17: Main
static void Main(string[] args)
{
Console.Title = "zmq Pub Sub Sample Client";
const string publishAddress = "tcp://127.0.0.1:54321";
const string listenAddress = "tcp://127.0.0.1:12345";
IMessageCodec messageCodec = new JsonMessageCodec(Encoding.Unicode);
IMessageBus messageBus = new MessageBus(listenAddress, publishAddress, messageCodec);
messageBus.Subscribe<object>(Console.WriteLine);
messageBus.GetMessages<StartedListeningMessage>()
.Where(m => m.Id == messageBus.GetHashCode())
.Subscribe(x => Console.WriteLine("Press ESC to cancel, or any other key to send a message."));
var worker = new BackgroundWorker();
worker.DoWork += (s, e) => messageBus.Listen();
worker.RunWorkerAsync();
bool loop = true;
int i = 1;
while (loop)
{
var key = Console.ReadKey(false);
if (key.Key == ConsoleKey.Escape)
{
loop = false;
continue;
}
string message = string.Format("Message {0:d2} from Client", i);
messageBus.Publish(message);
i++;
}
}
开发者ID:hotgazpacho,项目名称:zmqPubSub,代码行数:31,代码来源:Program.cs
示例18: HeavyLoadTest
public void HeavyLoadTest()
{
const int REPEATER_COUNT = 10;
const int MESSAGE_COUNT = 200;
// Arrange
var bus = new MessageBus();
var receivers = new MessageRepeater[REPEATER_COUNT];
for (var i = 0; i < REPEATER_COUNT; i++)
{
receivers[i] = new MessageRepeater(bus, i);
bus.SubscriberFor<RepeatingMessage>(receivers[i].Receive);
}
// Act
var messages = new RepeatingMessage[MESSAGE_COUNT];
for (var i = 0; i < MESSAGE_COUNT; i++)
{
messages[i] = new RepeatingMessage();
bus.SendMessage(messages[i]);
}
// Assert
var finished = false;
while (!finished)
{
System.Threading.Thread.Sleep(500);
var count = messages.Count(m => m.Counter == REPEATER_COUNT);
Console.WriteLine(count);
if (count == MESSAGE_COUNT)
finished = true;
}
}
开发者ID:TechnoTone,项目名称:MiniBus,代码行数:34,代码来源:MessageBus_CopesWithHeavyLoad.cs
示例19: GameObjectFactory
public GameObjectFactory(MessageBus bus)
{
GameObjects = new List<IGameObject>();
Bus = bus;
Initialise();
}
开发者ID:veggielane,项目名称:orts_old,代码行数:7,代码来源:GameObjectFactory.cs
示例20: PublishAndUnsubscribe
public void PublishAndUnsubscribe()
{
// Arrange
var bus = new MessageBus();
Action<Object> handler = null;
handler = (m) =>
{
Messages.Add(m);
// Unsubscribe during the publish handler.
bus.Unsubscribe<Object>(handler);
};
bus.Subscribe<Object>(handler);
bus.Subscribe<Object>((m) =>
{
Messages.Add(m);
});
// Act
var message = Guid.NewGuid().ToString();
bus.Publish<Object>(message);
bus.Publish<Object>(message);
// Assert
Assert.AreEqual(3, Messages.Count);
}
开发者ID:brentedwards,项目名称:Charmed,代码行数:26,代码来源:MessageBusTests.cs
注:本文中的MessageBus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论