Beispiel #1
0
    static async Task AsyncMain()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.WcfCallbacks");
        busConfiguration.UseSerialization <JsonSerializer>();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        #region startbus


        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusSession busSession = endpoint.CreateBusSession();

            using (StartWcfHost(busSession))
            {
                Console.WriteLine("Press any key to exit");
                Console.ReadKey();
            }
        }
        finally
        {
            await endpoint.Stop();
        }

        #endregion
    }
Beispiel #2
0
    static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 'J' to send a JSON message");
        Console.WriteLine("Press 'X' to send a XML message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key == ConsoleKey.X)
            {
                await SendXmlMessage(busSession);

                continue;
            }
            if (key.Key == ConsoleKey.J)
            {
                await SendJsonMessage(busSession);

                continue;
            }
            break;
        }
    }
Beispiel #3
0
    static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 'F' to send a message with a file stream");
        Console.WriteLine("Press 'H' to send a message with a http stream");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();

            if (key.Key == ConsoleKey.F)
            {
                await SendMessageWithFileStream(busSession);

                continue;
            }
            if (key.Key == ConsoleKey.H)
            {
                await SendMessageWithHttpStream(busSession);

                continue;
            }
            break;
        }
    }
Beispiel #4
0
    static async Task SendOrder(IBusSession busSession)
    {

        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                break;
            }
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id = id
            };
            await busSession.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));

        }

    }
Beispiel #5
0
        async Task <FeatureRunner> StartFeatures(IBusSession session)
        {
            var featureRunner = new FeatureRunner(featureActivator);
            await featureRunner.Start(builder, session).ConfigureAwait(false);

            return(featureRunner);
        }
Beispiel #6
0
        /// <summary>
        /// Sends the provided message.
        /// </summary>
        /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param>
        /// <param name="message">The message to send.</param>
        public static Task Send(this IBusSession session, object message)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(message), message);

            return(session.Send(message, new SendOptions()));
        }
Beispiel #7
0
        /// <summary>
        /// Instantiates a message of <typeparamref name="T" /> and sends it.
        /// </summary>
        /// <typeparam name="T">The type of message, usually an interface.</typeparam>
        /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param>
        /// <param name="messageConstructor">An action which initializes properties of the message.</param>
        /// <remarks>
        /// The message will be sent to the destination configured for <typeparamref name="T" />.
        /// </remarks>
        public static Task Send <T>(this IBusSession session, Action <T> messageConstructor)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(messageConstructor), messageConstructor);

            return(session.Send(messageConstructor, new SendOptions()));
        }
Beispiel #8
0
    static async Task SendOrder(IBusSession busSession)
    {
        Console.WriteLine("Press enter to send a message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key != ConsoleKey.Enter)
            {
                break;
            }
            Guid id = Guid.NewGuid();

            PlaceOrder placeOrder = new PlaceOrder
            {
                Product = "New shoes",
                Id      = id
            };
            await busSession.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
        }
    }
    static async Task SendMessage(IBusSession busSession)
    {
        Message message = new Message();
        await busSession.SendLocal(message);

        Console.WriteLine();
        Console.WriteLine("Message sent");
    }
Beispiel #10
0
        async Task <StartAndStoppablesRunner> StartStartables(IBusSession session)
        {
            var allStartables = builder.BuildAll <IWantToRunWhenBusStartsAndStops>().Concat(startables).ToList();
            var runner        = new StartAndStoppablesRunner(allStartables);
            await runner.Start(session).ConfigureAwait(false);

            return(runner);
        }
Beispiel #11
0
    static async Task SendMessage(IBusSession busSession)
    {
        Message message = new Message();
        await busSession.SendLocal(message);

        Console.WriteLine();
        Console.WriteLine("Message sent");
    }
Beispiel #12
0
 static IDisposable StartWcfHost(IBusSession busSession)
 {
     WcfMapper wcfMapper = new WcfMapper(busSession, "http://localhost:8080");
     wcfMapper.StartListening<EnumMessage, Status>();
     wcfMapper.StartListening<ObjectMessage, ReplyMessage>();
     wcfMapper.StartListening<IntMessage, int>();
     return wcfMapper;
 }
 // Shut down server before sending this message, after 30 seconds, the message will be moved to Transactional dead-letter messages queue.
 static async Task Expiration(IBusSession busSession)
 {
     await busSession.Send(new MessageThatExpires
              {
                  RequestId = new Guid()
              });
     Console.WriteLine("message with expiration was sent");
 }
 public Task Start(IBusSession session)
 {
     ErrorsNotifications errors = busNotifications.Errors;
     errors.MessageHasBeenSentToSecondLevelRetries += (sender, retry) => LogToConsole(retry);
     errors.MessageHasFailedAFirstLevelRetryAttempt += (sender, retry) => LogToConsole(retry);
     errors.MessageSentToErrorQueue += (sender, retry) => LogToConsole(retry);
     return Task.FromResult(0);
 }
    // Shut down server before sending this message, after 30 seconds, the message will be moved to Transactional dead-letter messages queue.
    static async Task Expiration(IBusSession busSession)
    {
        await busSession.Send(new MessageThatExpires
        {
            RequestId = new Guid()
        });

        Console.WriteLine("message with expiration was sent");
    }
        public Task Start(IBusSession session)
        {
            ErrorsNotifications errors = busNotifications.Errors;

            errors.MessageHasBeenSentToSecondLevelRetries  += (sender, retry) => LogToConsole(retry);
            errors.MessageHasFailedAFirstLevelRetryAttempt += (sender, retry) => LogToConsole(retry);
            errors.MessageSentToErrorQueue += (sender, retry) => LogToConsole(retry);
            return(Task.FromResult(0));
        }
    static IDisposable StartWcfHost(IBusSession busSession)
    {
        WcfMapper wcfMapper = new WcfMapper(busSession, "http://localhost:8080");

        wcfMapper.StartListening <EnumMessage, Status>();
        wcfMapper.StartListening <ObjectMessage, ReplyMessage>();
        wcfMapper.StartListening <IntMessage, int>();
        return(wcfMapper);
    }
Beispiel #18
0
        async Task SendInterface()
        {
            IBusSession busSession = null;

            #region BasicSendInterface
            await busSession.Send <IMyMessage>(m => m.MyProperty = "Hello world");

            #endregion
        }
        internal static void SetMessageSession(IMessageSession messageSession)
        {
            if (MessageSession != null)
            {
                throw new InvalidOperationException("Attempt to overwrite an existing message session in BusSession.Current.");
            }

            MessageSession = new MessageSession(messageSession);
        }
Beispiel #20
0
            protected override async Task OnStart(IBusSession session)
            {
                var result = await preStartupCheck().ConfigureAwait(false);

                if (!result.Succeeded)
                {
                    throw new Exception($"Pre start-up check failed: {result.ErrorMessage}");
                }
            }
    public static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 's' to send a valid message");
        Console.WriteLine("Press 'e' to send a failed message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine();
            switch (key.Key)
            {
            case ConsoleKey.S:
                #region SendingSmall
                await busSession.SendLocal(new CreateProductCommand
                {
                    ProductId   = "XJ128",
                    ProductName = "Milk",
                    ListPrice   = 4,
                    // 7MB. MSMQ should throw an exception, but it will not since the buffer will be compressed
                    // before it reaches MSMQ.
                    Image = new byte[1024 * 1024 * 7]
                });

                #endregion
                break;

            case ConsoleKey.E:
                try
                {
                    #region SendingLarge
                    await busSession.SendLocal(new CreateProductCommand
                    {
                        ProductId   = "XJ128",
                        ProductName = "Really long product name",
                        ListPrice   = 15,
                        // 7MB. MSMQ should throw an exception, but it will not since the buffer will be compressed
                        // before it reaches MSMQ.
                        Image = new byte[1024 * 1024 * 7]
                    });

                    #endregion
                }
                catch
                {
                    //so the console keeps on running
                }
                break;

            default:
            {
                return;
            }
            }
        }
    }
 static async Task SendJsonMessage(IBusSession busSession)
 {
     MessageWithJson message = new MessageWithJson
     {
         SomeProperty = "Some content in a json message",
     };
     await busSession.Send("Samples.MultiSerializer.Receiver", message);
     Console.WriteLine("Json Message sent");
 }
Beispiel #23
0
            protected override async Task OnStart(IBusSession session)
            {
                foreach (var eventType in eventsToSubscribe)
                {
                    await session.Subscribe(eventType).ConfigureAwait(false);

                    Logger.DebugFormat("Auto subscribed to event {0}", eventType);
                }
            }
    static async Task Start(IBusSession busSession)
    {
        Console.WriteLine("Press '1' to publish IEvent");
        Console.WriteLine("Press '2' to publish EventMessage");
        Console.WriteLine("Press '3' to publish AnotherEventMessage");
        Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");
        #region PublishLoop
        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            Guid eventId = Guid.NewGuid();
            switch (key.Key)
            {
            case ConsoleKey.D1:
                await busSession.Publish <IMyEvent>(m =>
                {
                    m.EventId  = eventId;
                    m.Time     = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null;
                    m.Duration = TimeSpan.FromSeconds(99999D);
                });

                Console.WriteLine("Published IMyEvent with Id {0}.", eventId);
                continue;

            case ConsoleKey.D2:
                EventMessage eventMessage = new EventMessage
                {
                    EventId  = eventId,
                    Time     = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
                    Duration = TimeSpan.FromSeconds(99999D)
                };
                await busSession.Publish(eventMessage);

                Console.WriteLine("Published EventMessage with Id {0}.", eventId);
                continue;

            case ConsoleKey.D3:
                AnotherEventMessage anotherEventMessage = new AnotherEventMessage
                {
                    EventId  = eventId,
                    Time     = DateTime.Now.Second > 30 ? (DateTime?)DateTime.Now : null,
                    Duration = TimeSpan.FromSeconds(99999D)
                };
                await busSession.Publish(anotherEventMessage);

                Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
                continue;

            default:
                return;
            }
        }
        #endregion
    }
Beispiel #25
0
    static async Task SendJsonMessage(IBusSession busSession)
    {
        MessageWithJson message = new MessageWithJson
        {
            SomeProperty = "Some content in a json message",
        };
        await busSession.Send("Samples.MultiSerializer.Receiver", message);

        Console.WriteLine("Json Message sent");
    }
Beispiel #26
0
        /// <summary>
        /// Instantiates a message of type T and sends it back to the current endpoint.
        /// </summary>
        /// <typeparam name="T">The type of message, usually an interface.</typeparam>
        /// <param name="session">Object being extended.</param>
        /// <param name="messageConstructor">An action which initializes properties of the message.</param>
        public static Task SendLocal <T>(this IBusSession session, Action <T> messageConstructor)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(messageConstructor), messageConstructor);

            var options = new SendOptions();

            options.RouteToThisEndpoint();

            return(session.Send(messageConstructor, options));
        }
Beispiel #27
0
        /// <summary>
        /// Sends the message back to the current endpoint.
        /// </summary>
        /// <param name="session">Object being extended.</param>
        /// <param name="message">The message to send.</param>
        public static Task SendLocal(this IBusSession session, object message)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNull(nameof(message), message);

            var options = new SendOptions();

            options.RouteToThisEndpoint();

            return(session.Send(message, options));
        }
    static async Task PublishEvent(IBusSession busSession)
    {
        Guid eventId = Guid.NewGuid();

        await busSession.Publish <IMyEvent>(m =>
        {
            m.EventId = eventId;
        });

        Console.WriteLine("Event published, id: " + eventId);
    }
    static async Task PublishEvent(IBusSession busSession)
    {
        Guid eventId = Guid.NewGuid();

        await busSession.Publish<IMyEvent>(m =>
        {
            m.EventId = eventId;
        });
        Console.WriteLine("Event published, id: " + eventId);

    }
    static async Task SendRequest(IBusSession busSession)
    {
        Guid requestId = Guid.NewGuid();

        await busSession.Send(new Request
        {
            RequestId = requestId
        });

        Console.WriteLine("Request sent id: " + requestId);
    }
    static async Task SendRequest(IBusSession busSession)
    {
        Guid requestId = Guid.NewGuid();

        await busSession.Send(new Request
        {
            RequestId = requestId
        });

        Console.WriteLine("Request sent id: " + requestId);
    }
Beispiel #32
0
    public static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 's' to send a valid message");
        Console.WriteLine("Press 'e' to send a failed message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();
            Console.WriteLine();
            switch (key.Key)
            {
                case ConsoleKey.S:
                    #region SendingSmall
                    await busSession.SendLocal(new CreateProductCommand
                    {
                        ProductId = "XJ128",
                        ProductName = "Milk",
                        ListPrice = 4,
                        // 7MB. MSMQ should throw an exception, but it will not since the buffer will be compressed 
                        // before it reaches MSMQ.
                        Image = new byte[1024 * 1024 * 7]
                    });
                    #endregion
                    break;
                case ConsoleKey.E:
                    try
                    {
                        #region SendingLarge
                        await busSession.SendLocal(new CreateProductCommand
                        {
                            ProductId = "XJ128",
                            ProductName = "Really long product name",
                            ListPrice = 15,
                            // 7MB. MSMQ should throw an exception, but it will not since the buffer will be compressed 
                            // before it reaches MSMQ.
                            Image = new byte[1024 * 1024 * 7]
                        });
                        #endregion
                    }
                    catch
                    {
                        //so the console keeps on running   
                    }
                    break;
                default:
                    {
                        return;
                    }
            }
        }
    }
    async Task StartBus()
    {
        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Samples.Callbacks.WebSender");
        busConfiguration.UseSerialization<JsonSerializer>();
        busConfiguration.UsePersistence<InMemoryPersistence>();
        busConfiguration.EnableInstallers();
        busConfiguration.SendFailedMessagesTo("error");

        Endpoint = await NServiceBus.Endpoint.Start(busConfiguration);
        BusSession = Endpoint.CreateBusSession();
    }
    static async Task SendEnumMessage(IBusSession busSession)
    {
        Console.WriteLine("Message sent");
        #region SendEnumMessage

        EnumMessage message = new EnumMessage();
        SendOptions sendOptions = new SendOptions();
        sendOptions.SetDestination("Samples.Callbacks.Receiver");
        Status status = await busSession.Request<Status>(message, sendOptions);
        Console.WriteLine("Callback received with status:" + status);
        #endregion
    }
Beispiel #35
0
 public Bus(IServiceProvider serviceProvider
            , IBusSession sessionAccessor
            , ICommandsEventsStore commandsEventsStore
            , IMetricService metricService
            , ITime time)
 {
     ServiceProvider     = serviceProvider;
     SessionAccessor     = sessionAccessor;
     CommandsEventsStore = commandsEventsStore;
     MetricService       = metricService;
     Time = time;
 }
Beispiel #36
0
        async void Simple()
        {
            IBusSession busSession  = null;
            SendOptions sendOptions = new SendOptions();

            #region EnumCallback
            Message message  = new Message();
            Status  response = await busSession.Request <Status>(message, sendOptions);

            Console.WriteLine("Callback received with response:" + response);
            #endregion
        }
Beispiel #37
0
    static async Task SendMessageTooLargePayload(IBusSession busSession)
    {
        #region SendMessageTooLargePayload

        AnotherMessageWithLargePayload message = new AnotherMessageWithLargePayload
        {
            LargeBlob = new byte[1024*1024*5] //5MB
        };
        await busSession.Send("Samples.DataBus.Receiver", message);

        #endregion
    }
    static async Task Data(IBusSession busSession)
    {
        Guid requestId = Guid.NewGuid();

        await busSession.Send(new LargeMessage
        {
            RequestId    = requestId,
            LargeDataBus = new byte[1024 * 1024 * 5]
        });

        Console.WriteLine("Request sent id: " + requestId);
    }
    static async Task SendMessageTooLargePayload(IBusSession busSession)
    {
        #region SendMessageTooLargePayload

        AnotherMessageWithLargePayload message = new AnotherMessageWithLargePayload
        {
            LargeBlob = new byte[1024 * 1024 * 5] //5MB
        };
        await busSession.Send("Samples.DataBus.Receiver", message);

        #endregion
    }
    static async Task Data(IBusSession busSession)
    {
        Guid requestId = Guid.NewGuid();

        await busSession.Send(new LargeMessage
        {
            RequestId = requestId,
            LargeDataBus = new byte[1024*1024*5]
        });

        Console.WriteLine("Request sent id: " + requestId);
    }
    static async Task SendCommand(IBusSession busSession)
    {
        Guid commandId = Guid.NewGuid();

        await busSession.Send(new MyCommand
        {
            CommandId       = commandId,
            EncryptedString = "Some sensitive information"
        });

        Console.WriteLine("Command sent id: " + commandId);
    }
Beispiel #42
0
        /// <summary>
        /// Instantiates a message of type T and sends it to the given destination.
        /// </summary>
        /// <typeparam name="T">The type of message, usually an interface.</typeparam>
        /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param>
        /// <param name="destination">The destination to which the message will be sent.</param>
        /// <param name="messageConstructor">An action which initializes properties of the message.</param>
        public static Task Send <T>(this IBusSession session, string destination, Action <T> messageConstructor)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNullAndEmpty(nameof(destination), destination);
            Guard.AgainstNull(nameof(messageConstructor), messageConstructor);

            var options = new SendOptions();

            options.SetDestination(destination);

            return(session.Send(messageConstructor, options));
        }
Beispiel #43
0
        /// <summary>
        /// Sends the message.
        /// </summary>
        /// <param name="session">The instance of <see cref="IBusSession" /> to use for the action.</param>
        /// <param name="destination">The address of the destination to which the message will be sent.</param>
        /// <param name="message">The message to send.</param>
        public static Task Send(this IBusSession session, string destination, object message)
        {
            Guard.AgainstNull(nameof(session), session);
            Guard.AgainstNullAndEmpty(nameof(destination), destination);
            Guard.AgainstNull(nameof(message), message);

            var options = new SendOptions();

            options.SetDestination(destination);

            return(session.Send(message, options));
        }
    static async Task SendObjectMessage(IBusSession busSession)
    {
        Console.WriteLine("Message sent");
        #region SendObjectMessage

        ObjectMessage message = new ObjectMessage();
        SendOptions sendOptions = new SendOptions();
        sendOptions.SetDestination("Samples.Callbacks.Receiver");
        ObjectResponseMessage response = await busSession.Request<ObjectResponseMessage>(message, sendOptions);
        Console.WriteLine("Callback received with response property value:" + response.Property);

        #endregion
    }
    static async Task SendIntMessage(IBusSession busSession)
    {
        Console.WriteLine("Message sent");
        #region SendIntMessage

        IntMessage message = new IntMessage();
        SendOptions sendOptions = new SendOptions();
        sendOptions.SetDestination("Samples.Callbacks.Receiver");
        int response = await busSession.Request<int>(message, sendOptions);
        Console.WriteLine("Callback received with response:" + response);

        #endregion
    }
    static void Start(IBusSession busSession)
    {
        Console.WriteLine("Press '1' to publish IEvent");
        Console.WriteLine("Press '2' to publish EventMessage");
        Console.WriteLine("Press '3' to publish AnotherEventMessage");
        Console.WriteLine("Press 'Enter' to publish a message.To exit, Ctrl + C");
        #region PublishLoop
        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            Guid eventId = Guid.NewGuid();
            switch (key.Key)
            {
                case ConsoleKey.D1:
                    busSession.Publish<IMyEvent>(m =>
                    {
                        m.EventId = eventId;
                        m.Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null;
                        m.Duration = TimeSpan.FromSeconds(99999D);
                    });
                    Console.WriteLine("Published IMyEvent with Id {0}.", eventId);
                    continue;
                case ConsoleKey.D2:
                    EventMessage eventMessage = new EventMessage
                    {
                        EventId = eventId,
                        Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                        Duration = TimeSpan.FromSeconds(99999D)
                    };
                    busSession.Publish(eventMessage);
                    Console.WriteLine("Published EventMessage with Id {0}.", eventId);
                    continue;
                case ConsoleKey.D3:
                    AnotherEventMessage anotherEventMessage = new AnotherEventMessage
                    {
                        EventId = eventId,
                        Time = DateTime.Now.Second > 30 ? (DateTime?) DateTime.Now : null,
                        Duration = TimeSpan.FromSeconds(99999D)
                    };
                    busSession.Publish(anotherEventMessage);
                    Console.WriteLine("Published AnotherEventMessage with Id {0}.", eventId);
                    continue;
                default:
                    return;
            }
        }
        #endregion
    }
 public async Task Start(IBusSession session)
 {
     Console.WriteLine("sending message...");
     for (int i = 0; i < 100; i++)
     {
         await session.SendLocal(new SearchGitHub
         {
             Repository = "NServiceBus",
             RepositoryOwner = "Particular",
             SearchFor = "IBus"
         });
     }
     Console.WriteLine("message sent.");
 }
    static IDisposable StartOwinHost(IBusSession busSession)
    {
        string baseUrl = "http://localhost:12345/";
        StartOptions startOptions = new StartOptions(baseUrl)
        {
            ServerFactory = "Microsoft.Owin.Host.HttpListener",
        };

        return WebApp.Start(startOptions, builder =>
        {
            builder.UseCors(CorsOptions.AllowAll);
            MapToBus(builder, busSession);
            MapToMsmq(builder);
        });
    }
Beispiel #49
0
    static async Task SendMessageLargePayload(IBusSession busSession)
    {
        #region SendMessageLargePayload

        MessageWithLargePayload message = new MessageWithLargePayload
        {
            SomeProperty = "This message contains a large blob that will be sent on the data bus",
            LargeBlob = new DataBusProperty<byte[]>(new byte[1024*1024*5]) //5MB
        };
        await busSession.Send("Samples.DataBus.Receiver", message);

        #endregion

        Console.WriteLine("Message sent, the payload is stored in: " + BasePath);
    }
    static async Task AsyncStart()
    {
        var busConfiguration = new BusConfiguration();
        busConfiguration.EndpointName("Store.ECommerce");
        busConfiguration.PurgeOnStartup(true);

        busConfiguration.ApplyCommonConfiguration();
        busConfiguration.SendFailedMessagesTo("error");

        Endpoint = await NServiceBus.Endpoint.Start(busConfiguration);
        BusSession = Endpoint.CreateBusSession();

        AreaRegistration.RegisterAllAreas();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
    static async Task SendMessageWithFileStream(IBusSession busSession)
    {
        #region send-message-with-file-stream

        MessageWithStream message = new MessageWithStream
        {
            SomeProperty = "This message contains a stream",
            StreamProperty = File.OpenRead("FileToSend.txt")
        };
        await busSession.Send("Samples.PipelineStream.Receiver", message);

        #endregion

        Console.WriteLine();
        Console.WriteLine("Message with file stream sent");
    }
    static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 'Enter' to send a Message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            if (key.Key == ConsoleKey.Enter)
            {
                await SendMessage(busSession);
                continue;
            }
            return;
        }
    }
    static async Task SendMessageWithHttpStream(IBusSession busSession)
    {
        #region send-message-with-http-stream

        using (WebClient webClient = new WebClient())
        {
            MessageWithStream message = new MessageWithStream
            {
                SomeProperty = "This message contains a stream",
                StreamProperty = webClient.OpenRead("http://www.particular.net")
            };
            await busSession.Send("Samples.PipelineStream.Receiver", message);
        }

        #endregion

        Console.WriteLine();
        Console.WriteLine("Message with http stream sent");
    }
    public static async Task Start(IBusSession busSession)
    {
        Console.WriteLine("Press 'E' to publish an event");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            switch (key.Key)
            {
                case ConsoleKey.E:
                    await PublishEvent(busSession);
                    continue;
            }
            return;
        }
    }
    static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 'F' to send a message with a file stream");
        Console.WriteLine("Press 'H' to send a message with a http stream");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();

            if (key.Key == ConsoleKey.F)
            {
                await SendMessageWithFileStream(busSession);
                continue;
            }
            if (key.Key == ConsoleKey.H)
            {
                await SendMessageWithHttpStream(busSession);
                continue;
            }
            break;
        }
    }
    public static async Task Start(IBusSession busSession)
    {
        Console.WriteLine("Press 'C' to send a command");
        Console.WriteLine("Press 'R' to send a request");
        Console.WriteLine("Press 'E' to send a message that is marked as Express");
        Console.WriteLine("Press 'D' to send a large message that is marked to be sent using Data Bus");
        Console.WriteLine("Press 'X' to send a message that is marked with expiration time.");
        Console.WriteLine("Press any key to exit");


        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            switch (key.Key)
            {
                case ConsoleKey.C:
                    await SendCommand(busSession);
                    continue;
                case ConsoleKey.R:
                    await SendRequest(busSession);
                    continue;
                case ConsoleKey.E:
                    await Express(busSession);
                    continue;
                case ConsoleKey.D:
                    await Data(busSession);
                    continue;
                case ConsoleKey.X:
                    await Expiration(busSession);
                    continue;
            }
            return;

        }
    }
    static async Task Run(IBusSession busSession)
    {
        Console.WriteLine("Press 'J' to send a JSON message");
        Console.WriteLine("Press 'X' to send a XML message");
        Console.WriteLine("Press any key to exit");

        while (true)
        {
            ConsoleKeyInfo key = Console.ReadKey();
            Console.WriteLine();

            if (key.Key == ConsoleKey.X)
            {
                await SendXmlMessage(busSession);
                continue;
            }
            if (key.Key == ConsoleKey.J)
            {
                await SendJsonMessage(busSession);
                continue;
            }
            break;
        }
    }
    static async Task SendCommand(IBusSession busSession)
    {
        Guid commandId = Guid.NewGuid();

        await busSession.Send(new MyCommand
                 {
                     CommandId = commandId,
                     EncryptedString = "Some sensitive information"
                 });

        Console.WriteLine("Command sent id: " + commandId);
    }
Beispiel #59
0
 protected override async Task OnStop(IBusSession session)
 {
     resetEvent.Reset();
 }
Beispiel #60
0
 protected override async Task OnStart(IBusSession session)
 {
     resetEvent.Set();
 }