IBusControl CreateBus() { return(MassTransit.Bus.Factory.CreateUsingInMemory(x => { _inMemoryTransportCache = new InMemoryTransportCache(Environment.ProcessorCount); x.SetTransportProvider(_inMemoryTransportCache); ConfigureBus(x); x.ReceiveEndpoint("input_queue", ConfigureInputQueueEndpoint); })); }
private static IBusControl ConfigureBus() { var inMemoryTransportCache = new InMemoryTransportCache(Environment.ProcessorCount); return(Bus.Factory.CreateUsingInMemory(cfg => { cfg.SetTransportProvider(inMemoryTransportCache); cfg.ReceiveEndpoint("Test", configurator => { configurator.Consumer(() => new UserGreetings(new ConsoleGreetingSender())); }); })); }
public IBusControl CreateBus() { if (_receiveTransportProvider == null || _sendTransportProvider == null) { var transportProvider = new InMemoryTransportCache(_concurrencyLimit); _hosts.Add(transportProvider); _receiveTransportProvider = _receiveTransportProvider ?? transportProvider; _sendTransportProvider = _sendTransportProvider ?? transportProvider; } var builder = new InMemoryBusBuilder(_receiveTransportProvider, _sendTransportProvider, _hosts.ToArray(), ConsumePipeFactory, SendPipeFactory, PublishPipeFactory); foreach (var configurator in _configurators) { configurator.Apply(builder); } return(builder.Build()); }
public IBusControl CreateBus() { if (_receiveTransportProvider == null || _sendTransportProvider == null) { var transportProvider = new InMemoryTransportCache(_concurrencyLimit); _hosts.Add(transportProvider); _receiveTransportProvider = _receiveTransportProvider ?? transportProvider; _sendTransportProvider = _sendTransportProvider ?? transportProvider; } var builder = new InMemoryBusBuilder(_receiveTransportProvider, _sendTransportProvider, _hosts, _consumePipeSpecification); foreach (IInMemoryBusFactorySpecification configurator in _configurators) { configurator.Apply(builder); } return(builder.Build()); }
public async Task Should_be_able_to_consume_messages_polymorphically_if_the_receiving_bus_support_the_binary_serializer() { var inMemoryTransportCache = new InMemoryTransportCache(Environment.ProcessorCount); var consumed = new TaskCompletionSource <Base>(); var sourceBus = Bus.Factory.CreateUsingInMemory(x => { x.SetTransportProvider(inMemoryTransportCache); x.UseBinarySerializer(); }); var recvBus = Bus.Factory.CreateUsingInMemory(x => { x.SetTransportProvider(inMemoryTransportCache); x.SupportBinaryMessageDeserializer(); x.UseJsonSerializer(); x.ReceiveEndpoint("input_queue", configurator => { #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously configurator.Handler <Base>(async ctx => { consumed.TrySetResult(ctx.Message); }); #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously }); }); await sourceBus.StartAsync(); await recvBus.StartAsync(); // Create a recursive list var head = new ListNode { Value = 100 }; var tail = new ListNode { Next = head, Value = 200 }; head.Next = tail; var messageToSend = new Derived() { PropBase = 10, PropDerived = 20, Head = head }; await sourceBus.Publish(messageToSend); var completedTask = await Task.WhenAny(consumed.Task, Task.Delay(250)); Assert.AreEqual(consumed.Task, completedTask, "Timeout while waiting to receive the message sent on the source bus."); var message = await consumed.Task; Assert.NotNull(message); Assert.AreEqual(messageToSend.PropBase, message.PropBase); Assert.AreEqual(head.Value, message.Head.Value); Assert.AreEqual(tail.Value, message.Head.Next.Value); Assert.AreEqual(head.Value, message.Head.Next.Next.Value); await sourceBus.StopAsync(); await recvBus.StopAsync(); }