コード例 #1
0
        static void Main(string[] args)
        {
            IBus messaging = null;

            Configure.Serialization.Json();
            var config = Configure.With()
                         .DefineEndpointName("OnPremiseService1.EnvironmentMessageHandler")
                         .DefaultBuilder()
                         .DefiningEventsAs(t => t != null && t.Namespace != null && t.Namespace.EndsWith("Public.Events"))
                         .DefiningCommandsAs(t => t != null && t.Namespace != null && t.Namespace.EndsWith("Public.Commands"))
                         .MsmqSubscriptionStorage()
                         .InMemorySagaPersister()
                         .UseInMemoryGatewayPersister()
                         .UseInMemoryTimeoutPersister()
                         .UseTransport <Msmq>()
                         /*.Log4Net()*/;

            using (var lifetimeManagement = config.UnicastBus().CreateBus())
            {
                messaging = lifetimeManagement.Start(() => config.ForInstallationOn <Windows>().Install());

                Console.Title = "OnPremiseService1 - Demo - Inputs: '1', '2', 'q'";
                ConsoleKeyInfo consoleKey;

                do
                {
                    consoleKey = Console.ReadKey(true);
                    switch (consoleKey.KeyChar)
                    {
                    case '1':
                        DemoPrintouts.Begin("Sending command ... ");
                        messaging.Send <Commands.MutateValue>(v =>
                        {
                            v.Operator = Operator.Add;
                            v.Operand  = 5;
                        });
                        break;

                    case '2':
                        DemoPrintouts.Begin("Sending command ... ");
                        messaging.Send <CloudService1.Public.Commands.PleaseRepeatThis>(r =>
                        {
                            r.Phrase = "Orange";
                        });
                        break;

                    default:
                        break;
                    }
                } while (consoleKey.Key != ConsoleKey.Q);


                lifetimeManagement.Shutdown();
            }
        }
コード例 #2
0
ファイル: RelayEchoResponse.cs プロジェクト: IfInsurance/xdc
        public void Handle(BrokeredMessage message)
        {
            DemoPrintouts.Begin("Relaying Echo Response Event ... ");
            var echoedResponse = message.To <EchoedResponseModel>().Result;

            foreach (var property in message.Properties)
            {
                _bus.SetMessageHeader(echoedResponse, property.Key, property.Value.ToString());
            }

            _bus.Publish <EchoedResponse>(echoedResponse);
            message.Complete();
            DemoPrintouts.End("Done!");
        }
コード例 #3
0
ファイル: RelayEchoCommand.cs プロジェクト: IfInsurance/xdc
        public void Handle(PleaseRepeatThis message)
        {
            DemoPrintouts.Begin("Relaying Echo Command ... ");

            var brokeredMessage = Interop.CreateMessage(message, Bus.CurrentMessageContext.Id);

            // Break free from the local transaction and unconditionally send this message.
            // If it fails (throws an exception, we'll try again)
            // If it succeeds AND throws an exception, ASB's Duplicate message detection will take discard the duplicate message
            using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
            {
                MessageSender.Send(brokeredMessage);
                scope.Complete();
                DemoPrintouts.End("Done!");
            }
        }
コード例 #4
0
        public static void Handle(BrokeredMessage message, IBus bus)
        {
            DemoPrintouts.Begin("Relaying Math Command ... ");

            var mutateValueModel = message.To <MutateValueCommandModel>().Result;

            bus.Send <MutateValue>(value => {
                value.Operand  = mutateValueModel.Operand;
                value.Operator = mutateValueModel.Operator;

                //foreach (var property in message.Properties)
                //{
                //    bus.SetMessageHeader(value, property.Key, property.Value.ToString());
                //}
            });

            message.Complete();
            DemoPrintouts.End("Done!");
        }