本文整理汇总了C#中Bus.Send方法的典型用法代码示例。如果您正苦于以下问题:C# Bus.Send方法的具体用法?C# Bus.Send怎么用?C# Bus.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bus
的用法示例。
在下文中一共展示了Bus.Send方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public static void Init()
{
var bus = new Bus();
var cashier = new Cashier(bus);
var barista = new Barista(Guid.NewGuid(), bus);
var repository = new SagaRepository<OrderFufillment>(bus);
bus.RouteToSaga(repository, (DrinkOrdered e) => e.OrderId);
bus.RouteToSaga(repository, (DrinkPrepared e) => e.OrderId);
bus.RouteToSaga(repository, (PaymentReceived e) => e.OrderId);
bus.Register<OrderDrink>(c => cashier.Order(c.OrderId, c.Drink));
bus.RegisterOnThreadPool<Pay>(c => cashier.Pay(c.OrderId, PaymentMethod.CreditCard, c.Amount));
bus.RegisterOnThreadPool<PrepareDrink>(c => barista.PrepareDrink(c.OrderId, c.Drink));
bus.Register<NotifyCustomer>(c =>
{
Console.WriteLine("{0} is ready", c.OrderId);
ThreadPool.QueueUserWorkItem(_ => bus.Send(new Pay
{
OrderId =
c.OrderId,
Amount = 12m
}));
});
ServiceLocator.RegisterDispatcher<Command>(bus.Send);
WindowsCommunicationFoundation.RegisterServiceLayer<Sales>();
}
示例2: Send_Null_Throws
public void Send_Null_Throws()
{
var transport = A.Fake<ITransport>();
var bus = new Bus("myQueue");
bus.Transport = transport;
bus.Start();
Assert.Throws<ArgumentNullException>(() => bus.Send<string>(null));
}
示例3: Send_NotConfigured_Throws
public void Send_NotConfigured_Throws()
{
var transport = A.Fake<ITransport>();
var bus = new Bus("myQueue");
bus.Transport = transport;
string someData = "some made up data";
Assert.Throws<InvalidOperationException>(() => bus.Send(someData));
}
示例4: Main
private static void Main(string[] args)
{
var bus = new Bus();
var cashier = new Cashier(bus);
var barista = new Barista(Guid.NewGuid(), bus);
var repository = new SagaRepository<OrderFufillment>(bus);
bus.RouteToSaga(repository, (DrinkOrdered e) => e.OrderId);
bus.RouteToSaga(repository, (DrinkPrepared e) => e.OrderId);
bus.RouteToSaga(repository, (PaymentReceived e) => e.OrderId);
bus.Register<OrderDrink>(c => cashier.Order(c.OrderId, c.Drink));
bus.RegisterOnThreadPool<Pay>(c => cashier.Pay(c.OrderId, PaymentMethod.CreditCard, c.Amount));
bus.RegisterOnThreadPool<PrepareDrink>(c => barista.PrepareDrink(c.OrderId, c.Drink));
bus.Register<NotifyCustomer>(c =>
{
Console.WriteLine("{0} is ready", c.OrderId);
ThreadPool.QueueUserWorkItem(_ => bus.Send(new Pay
{
OrderId =
c.OrderId,
Amount = 12m
}));
});
Guid orderId = Guid.NewGuid();
bus.Send(new OrderDrink {Drink = Drinks.Cappucino, OrderId = orderId});
bus.Send(new Pay
{
OrderId = orderId,
Amount = 10m
});
Console.ReadLine();
}
示例5: OrderAPizza
private static async Task OrderAPizza(Bus bus)
{
Console.WriteLine("What's the customer's name?");
var customerName = Console.ReadLine().Trim();
if (string.IsNullOrWhiteSpace(customerName))
{
Console.WriteLine("You need to enter a customer name.");
return;
}
var command = new OrderPizzaCommand {CustomerName = customerName};
await bus.Send(command);
Console.WriteLine("Pizza ordered for {0}", customerName);
}
示例6: Main
static void Main(string[] args)
{
var message = new DummyMessage { Text = "Hello from Tuc Tuc!" };
string queue = Path.Combine(Path.GetTempPath(), "TucTuc");
var bus = new Bus(queue);
bus.RegisterEndpoint<DummyMessage>(queue);
bus.RegisterMessageHandler<DummyMessage>(m => Handle(m));
bus.Start();
while(true)
{
bus.Send(message);
Thread.Sleep(60000);
}
}
示例7: Should_throw_when_write_queues_are_undefined
public void Should_throw_when_write_queues_are_undefined()
{
var emptyWriteQueueList = new FakeValidMessageQueue[] { };
var bus = new Bus(new BusConfig(), new NullLogger(), new FakeValidMessageQueue(), new FakeValidMessageQueue(), emptyWriteQueueList);
var exception = Assert.Throws<BusException>(() => bus.Send(new FakeDto()));
Assert.That(exception.Message, Is.EqualTo("Bus has not been configured for sending messages. Did you forget to call DefineWriteQueue on BusBuilder?"));
}
示例8: Should_place_on_next_write_queue_if_auto_distribute_configured
public void Should_place_on_next_write_queue_if_auto_distribute_configured()
{
var msg = new FakeDto();
var writeQueues = new[] { new FakeValidMessageQueue(), new FakeValidMessageQueue(), new FakeValidMessageQueue() };
var bus = new Bus(new FakeBusConfig { AutoDistributeOnSend = true }, new NullLogger(), new FakeValidMessageQueue(), new FakeValidMessageQueue(), writeQueues);
bus.Send(msg);
Assert.That(writeQueues[0].Count, Is.EqualTo(1));
Assert.That(writeQueues[1].Count, Is.EqualTo(0));
Assert.That(writeQueues[2].Count, Is.EqualTo(0));
bus.Send(msg);
Assert.That(writeQueues[0].Count, Is.EqualTo(1));
Assert.That(writeQueues[1].Count, Is.EqualTo(1));
Assert.That(writeQueues[2].Count, Is.EqualTo(0));
bus.Send(msg);
Assert.That(writeQueues[0].Count, Is.EqualTo(1));
Assert.That(writeQueues[1].Count, Is.EqualTo(1));
Assert.That(writeQueues[2].Count, Is.EqualTo(1));
}
示例9: Should_place_on_a_single_queue
public void Should_place_on_a_single_queue()
{
var msg = new FakeDto();
var writeQueues = new[] { new FakeValidMessageQueue() };
var bus = new Bus(new FakeBusConfig(), new NullLogger(), new FakeValidMessageQueue(), new FakeValidMessageQueue(), writeQueues);
bus.Send(msg);
Assert.That(writeQueues[0].Count, Is.EqualTo(1));
}
示例10: Should_log_all_steps_involved
public void Should_log_all_steps_involved()
{
var logger = new FakeLogger();
var msg = new FakeDto();
var writeQueues = new[] { new FakeValidMessageQueue() };
var bus = new Bus(new FakeBusConfig(), logger, new FakeValidMessageQueue(), new FakeValidMessageQueue(), writeQueues);
bus.Send(msg);
Assert.That(logger[0], Is.StringEnding("Transaction started"));
Assert.That(logger[1], Is.StringEnding("Started SEND Operation"));
Assert.That(logger[2], Is.StringEnding("Payload: FakeDto"));
Assert.That(logger[3], Is.StringEnding("Sent to queue: FakeValidMessageQueue"));
Assert.That(logger[4], Is.StringEnding("Completed SEND Operation"));
Assert.That(logger[5], Is.StringEnding("Transaction committed"));
}