コード例 #1
0
    static async Task SendOrder(IBusContext busContext)
    {
        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 busContext.Send("Samples.StepByStep.Server", placeOrder);

            Console.WriteLine("Sent a new PlaceOrder message with id: {0}", id.ToString("N"));
        }
    }
コード例 #2
0
    static async Task AsyncMain()
    {
        #region non-transactional

        BusConfiguration busConfiguration = new BusConfiguration();
        busConfiguration.UseTransport <MsmqTransport>()
        .Transactions(TransportTransactionMode.None);

        #endregion

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

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext busContext = endpoint.CreateBusContext();
            await busContext.Send("Samples.MessageDurability.Receiver", new MyMessage());

            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
コード例 #3
0
    static async Task AsyncMain()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.MessageBodyEncryption.Endpoint1");
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.RegisterMessageEncryptor();
        busConfiguration.SendFailedMessagesTo("error");
        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext   busContext    = endpoint.CreateBusContext();
            CompleteOrder completeOrder = new CompleteOrder
            {
                CreditCard = "123-456-789"
            };
            await busContext.Send("Samples.MessageBodyEncryption.Endpoint2", completeOrder);

            Console.WriteLine("Message sent");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
コード例 #4
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(IBusContext bus)
    {
        await bus.Send(new MessageThatExpires
        {
            RequestId = new Guid()
        });

        Console.WriteLine("message with expiration was sent");
    }
コード例 #5
0
    static async Task SendJsonMessage(IBusContext busContext)
    {
        MessageWithJson message = new MessageWithJson
        {
            SomeProperty = "Some content in a json message",
        };
        await busContext.Send("Samples.MultiSerializer.Receiver", message);

        Console.WriteLine("Json Message sent");
    }
コード例 #6
0
    static async Task SendRequest(IBusContext bus)
    {
        Guid requestId = Guid.NewGuid();

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

        Console.WriteLine("Request sent id: " + requestId);
    }
コード例 #7
0
        public async Task RequestImmediateDispatch()
        {
            IBusContext busContext = null;

            #region RequestImmediateDispatch
            var options = new SendOptions();
            options.RequireImmediateDispatch();
            await busContext.Send(new MyMessage(), options);

            #endregion
        }
コード例 #8
0
    static async Task Data(IBusContext bus)
    {
        Guid requestId = Guid.NewGuid();

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

        Console.WriteLine("Request sent id: " + requestId);
    }
コード例 #9
0
        async Task DisablePerMessage()
        {
            IBusContext busContext = null;

            #region DisableBestPracticeEnforcementPerMessage
            SendOptions options = new SendOptions();

            options.DoNotEnforceBestPractices();

            await busContext.Send(new MyEvent(), options);
            #endregion
        }
コード例 #10
0
    static async Task SendMessageTooLargePayload(IBusContext bus)
    {
        #region SendMessageTooLargePayload

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

        #endregion
    }
コード例 #11
0
    static async Task SendCommand(IBusContext bus)
    {
        Guid commandId = Guid.NewGuid();

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

        Console.WriteLine("Command sent id: " + commandId);
    }
コード例 #12
0
        public async Task Correlation()
        {
            IBusContext busContext = null;

            #region custom-correlationid
            SendOptions options = new SendOptions();

            options.SetCorrelationId("My custom correlation id");

            await busContext.Send(new MyRequest(), options);

            #endregion
        }
コード例 #13
0
        static Task DeferTask(TaskDefinition taskDefinition, IBusContext bus)
        {
            var options = new SendOptions();

            options.DelayDeliveryWith(taskDefinition.Every);
            options.RouteToLocalEndpointInstance();

            return(bus.Send(new ScheduledTask
            {
                TaskId = taskDefinition.Id,
                Name = taskDefinition.Name,
                Every = taskDefinition.Every
            }, options));
        }
コード例 #14
0
    static async Task AsyncMain()
    {
        LogManager.Use <DefaultFactory>()
        .Level(LogLevel.Info);
        BusConfiguration busConfiguration = new BusConfiguration();

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

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext busContext = endpoint.CreateBusContext();
            Console.WriteLine("Press enter to send a message");
            Console.WriteLine("Press any key to exit");

            #region ClientLoop

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

                if (key.Key != ConsoleKey.Enter)
                {
                    return;
                }
                Guid guid = Guid.NewGuid();
                Console.WriteLine("Requesting to get data by id: {0}", guid.ToString("N"));

                RequestDataMessage message = new RequestDataMessage
                {
                    DataId = guid,
                    String = "String property value"
                };
                await busContext.Send("Samples.FullDuplex.Server", message);
            }

            #endregion
        }
        finally
        {
            await endpoint.Stop();
        }
    }
コード例 #15
0
    static async Task SendMessageLargePayload(IBusContext bus)
    {
        #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 bus.Send("Samples.DataBus.Receiver", message);

        #endregion

        Console.WriteLine("Message sent, the payload is stored in: " + BasePath);
    }
コード例 #16
0
    static async Task SendMessageWithFileStream(IBusContext busContext)
    {
        #region send-message-with-file-stream

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

        #endregion

        Console.WriteLine();
        Console.WriteLine("Message with file stream sent");
    }
コード例 #17
0
    static async Task AsyncMain()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

        busConfiguration.EndpointName("Samples.Encryption.Endpoint1");
        busConfiguration.RijndaelEncryptionService();
        busConfiguration.UsePersistence <InMemoryPersistence>();
        busConfiguration.SendFailedMessagesTo("error");
        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext           busContext = endpoint.CreateBusContext();
            MessageWithSecretData message    = new MessageWithSecretData
            {
                Secret      = "betcha can't guess my secret",
                SubProperty = new MySecretSubProperty
                {
                    Secret = "My sub secret"
                },
                CreditCards = new List <CreditCardDetails>
                {
                    new CreditCardDetails
                    {
                        ValidTo = DateTime.UtcNow.AddYears(1),
                        Number  = "312312312312312"
                    },
                    new CreditCardDetails
                    {
                        ValidTo = DateTime.UtcNow.AddYears(2),
                        Number  = "543645546546456"
                    }
                }
            };
            await busContext.Send("Samples.Encryption.Endpoint2", message);

            Console.WriteLine("MessageWithSecretData sent. Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpoint.Stop();
        }
    }
コード例 #18
0
    static async Task SendMessageWithHttpStream(IBusContext busContext)
    {
        #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 busContext.Send("Samples.PipelineStream.Receiver", message);
        }

        #endregion

        Console.WriteLine();
        Console.WriteLine("Message with http stream sent");
    }
コード例 #19
0
    static async Task AsyncMain()
    {
        BusConfiguration busConfiguration = new BusConfiguration();

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

        IEndpointInstance endpoint = await Endpoint.Start(busConfiguration);

        try
        {
            IBusContext busContext = endpoint.CreateBusContext();
            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)
                {
                    return;
                }
                Guid id = Guid.NewGuid();

                await busContext.Send("Samples.FaultTolerance.Server", new MyMessage
                {
                    Id = id
                });

                Console.WriteLine("Sent a new message with id: {0}", id.ToString("N"));
            }
        }
        finally
        {
            await endpoint.Stop();
        }
    }
コード例 #20
0
 public async Task Send(object message) => await _context.Send(message);