Exemple #1
0
        public SendActivity(Uri destinationAddress, EventMessageFactory <TInstance, TMessage> messageFactory, Action <SendContext <TMessage> > contextCallback)
        {
            _destinationAddressProvider = _ => destinationAddress;
            _messageFactory             = messageFactory;

            _sendPipe = Pipe.Execute(contextCallback);
        }
Exemple #2
0
        public SendActivity(DestinationAddressProvider <TInstance> destinationAddressProvider, EventMessageFactory <TInstance, TMessage> messageFactory)
        {
            _destinationAddressProvider = destinationAddressProvider;
            _messageFactory             = messageFactory;

            _sendPipe = Pipe.Empty <SendContext <TMessage> >();
        }
Exemple #3
0
        public SendActivity(Uri destinationAddress, EventMessageFactory <TInstance, TMessage> messageFactory)
        {
            _destinationAddress = destinationAddress;
            _messageFactory     = messageFactory;

            _sendPipe = Pipe.Empty <SendContext <TMessage> >();
        }
Exemple #4
0
        public RespondActivity(EventMessageFactory <TInstance, TData, TMessage> messageFactory,
                               Action <SendContext <TMessage> > contextCallback)
        {
            _messageFactory = messageFactory;

            _responsePipe = Pipe.Execute(contextCallback);
        }
        public ScheduleActivity(EventMessageFactory <TInstance, TMessage> messageFactory, Schedule <TInstance> schedule)
        {
            _messageFactory = messageFactory;
            _schedule       = schedule;

            _sendPipe = Pipe.Empty <SendContext>();
        }
Exemple #6
0
 public static EventActivityBinder <TInstance> Publish <TInstance, TMessage>(this EventActivityBinder <TInstance> source,
                                                                             EventMessageFactory <TInstance, TMessage> messageFactory, Action <PublishContext <TMessage> > contextCallback = null)
     where TInstance : class, SagaStateMachineInstance
     where TMessage : class
 {
     return(source.Add(new PublishActivity <TInstance, TMessage>(messageFactory, contextCallback)));
 }
Exemple #7
0
 public static EventActivityBinder <TInstance> Send <TInstance, TMessage>(this EventActivityBinder <TInstance> source, Uri destinationAddress,
                                                                          EventMessageFactory <TInstance, TMessage> messageFactory, Action <SendContext <TMessage> > contextCallback)
     where TInstance : class, SagaStateMachineInstance
     where TMessage : class
 {
     return(source.Add(new SendActivity <TInstance, TMessage>(destinationAddress, messageFactory, contextCallback)));
 }
        public void TestOrderServiceSuccessRunAndStop()
        {
            var service  = new OrderService();
            var producer = new Producer(service.Disruptor.RingBuffer);

            Task.Run(() => service.Run());

            for (int i = 0; i < 10; i++)
            {
                var msg = EventMessageFactory.GetEventMessage();
                msg.EventType                 = EventType.OrderPlaced;
                msg.EventData.Order.Id        = i;
                msg.EventData.Order.Price     = 100;
                msg.EventData.Order.AccountId = 1000001;

                producer.OnData(msg);
            }

            service.Stop();

            var actual = service.Disruptor.RingBuffer.ClaimAndGetPreallocated(9);

            Assert.Multiple(() =>
            {
                Assert.That(actual.EventType, Is.EqualTo(EventType.OrderPlaced));
                Assert.That(actual.EventData.Order.Id, Is.EqualTo(9));
                Assert.That(actual.EventData.Order.Price, Is.EqualTo(100));
            });
        }
Exemple #9
0
        private static void SendEventMessage()
        {
            var originObject = new UpdatePurchaseOrderStatusByBillIdMqContract()
            {
                UpdatePurchaseOrderStatusType = 1,
                RelationBillType = 10,
                RelationBillId   = 10016779,
                UpdateStatus     = 30,
                ModifiedBy       = 100
            };

            var sendMessage = EventMessageFactory.CreateEventMessageInstance(originObject, "Test");

            RabbitMqClient.Instance.TriggerEventMessage(sendMessage, "", "Demo.J");
            //for (int i = 0; i < 100; i++)
            //{
            //    var originObject = new UpdatePurchaseOrderStatusByBillIdMqContract()
            //    {
            //        UpdatePurchaseOrderStatusType = 1,
            //        RelationBillType = 10,
            //        RelationBillId = 10016779,
            //        UpdateStatus = 30,
            //        ModifiedBy = i
            //    };

            //    var sendMessage = EventMessageFactory.CreateEventMessageInstance(originObject, "Test");
            //    RabbitMqClient.Instance.TriggerEventMessage(sendMessage, "Demo.Purchase", "Demo.Purchase");
            //}
        }
 public RequestActivity(Request <TInstance, TRequest, TResponse> request, ServiceAddressProvider <TInstance> serviceAddressProvider,
                        EventMessageFactory <TInstance, TRequest> messageFactory)
     : base(request)
 {
     _messageFactory         = messageFactory;
     _serviceAddressProvider = context => serviceAddressProvider(context) ?? request.Settings.ServiceAddress;
 }
Exemple #11
0
        /// <summary>
        /// Send
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            object originObject = Guid.NewGuid().ToString() + "AUTO";
            var    sendMessage  = EventMessageFactory.CreateEventMessageInstance(originObject, "AUTO");

            AutoMQClient.Instance.TriggerEventMessage(sendMessage, "AUTO", "AUTO");
            //var conn = new ConnectionFactory() { HostName = "127.0.0.1" };
            //using (var connmodel = conn.CreateConnection())
            //{
            //    using (var channel = connmodel.CreateModel())
            //    {
            //        channel.QueueDeclare(queue: "CALC",
            //                     durable: false,
            //                     exclusive: false,
            //                     autoDelete: false,
            //                     arguments: null);

            //        string messageGUID = Guid.NewGuid().ToString();
            //        textBox1.Text = messageGUID;
            //        var body = Encoding.UTF8.GetBytes(messageGUID);
            //        channel.BasicPublish(exchange: "",
            //                             routingKey: "CALC",
            //                             basicProperties: null,
            //                             body: body);
            //        //MessageBox.Show("send"+ messageGUID);
            //    }
            //}
        }
Exemple #12
0
 public static EventActivityBinder <TInstance> Send <TInstance, TMessage>(this EventActivityBinder <TInstance> source,
                                                                          EventMessageFactory <TInstance, TMessage> messageFactory)
     where TInstance : class, SagaStateMachineInstance
     where TMessage : class
 {
     return(source.Add(new SendActivity <TInstance, TMessage>(messageFactory)));
 }
Exemple #13
0
        public PublishActivity(EventMessageFactory <TInstance, TMessage> messageFactory,
                               Action <PublishContext <TMessage> > contextCallback)
        {
            _messageFactory = messageFactory;

            _publishPipe = Pipe.Execute(contextCallback);
        }
Exemple #14
0
        private async Task PublishEventsAsync()
        {
            if (publishedEvents.Count > 0)
            {
                if (EventBuffer == null)
                {
                    throw new InvalidOperationException($"Cannot publish events from {this} because its {nameof(EventBuffer)} has not been set");
                }

                if (EventMessageFactory == null)
                {
                    throw new InvalidOperationException($"Cannot publish events from {this} because its {nameof(EventMessageFactory)} has not been set");
                }
            }

            foreach (var ev in publishedEvents)
            {
                var eventMessage = await EventMessageFactory.CreateMessageAsync(ev);

                if (eventMessage.Metadata.GetEventId() == null)
                {
                    eventMessage.SetMetadata(BasicEventMetadataNames.EventId, Guid.NewGuid().ToString());
                }

                EventBuffer.PushEvent(eventMessage);
            }
        }
Exemple #15
0
 public static EventActivityBinder <TInstance, TData> Publish <TInstance, TData, TMessage>(
     this EventActivityBinder <TInstance, TData> source, EventMessageFactory <TInstance, TData, TMessage> messageFactory)
     where TInstance : class, SagaStateMachineInstance
     where TData : class
     where TMessage : class
 {
     return(source.Add(new PublishActivity <TInstance, TData, TMessage>(messageFactory)));
 }
        public ScheduleActivity(EventMessageFactory <TInstance, TMessage> messageFactory, Schedule <TInstance> schedule,
                                Action <SendContext> contextCallback)
        {
            _messageFactory = messageFactory;
            _schedule       = schedule;

            _sendPipe = Pipe.Execute(contextCallback);
        }
Exemple #17
0
 public static EventActivityBinder <TInstance, TData> Schedule <TInstance, TData, TMessage>(
     this EventActivityBinder <TInstance, TData> source, Schedule <TInstance, TMessage> schedule,
     EventMessageFactory <TInstance, TData, TMessage> messageFactory, ScheduleDelayProvider <TInstance, TData> delayProvider)
     where TInstance : class, SagaStateMachineInstance
     where TData : class
     where TMessage : class
 {
     return(source.Add(new ScheduleActivity <TInstance, TData, TMessage>(messageFactory, schedule, delayProvider)));
 }
Exemple #18
0
        public ScheduleActivity(EventMessageFactory <TInstance, TMessage> messageFactory, Schedule <TInstance> schedule,
                                ScheduleDelayProvider <TInstance> delayProvider)
        {
            _messageFactory = messageFactory;
            _schedule       = schedule;
            _delayProvider  = delayProvider;

            _sendPipe = Pipe.Empty <SendContext>();
        }
Exemple #19
0
        /// <summary>
        /// 向消息队列发送有关QuestionsLibraryAndSort添加或删除的消息
        /// </summary>
        /// <param name="mi"></param>
        public static void SendEventMessageByQuestionsLibraryAndSort(MessageInfo mi)
        {
            var sendMessage =
                EventMessageFactory.CreateEventMessageInstance <MessageInfo>(mi, MessageType.Markcode);

            RabbitMqClient.Instance.TriggerEventMessage(sendMessage, "", RabbitMQCMSRedBag);

            //EventLog.Log("添加消息:" + mi.Content, "mq");
        }
Exemple #20
0
 public static EventActivityBinder <TInstance, TData> Respond <TInstance, TData, TMessage>(
     this EventActivityBinder <TInstance, TData> source, EventMessageFactory <TInstance, TData, TMessage> messageFactory,
     Action <SendContext <TMessage> > contextCallback)
     where TInstance : class, SagaStateMachineInstance
     where TData : class
     where TMessage : class
 {
     return(source.Add(new RespondActivity <TInstance, TData, TMessage>(messageFactory, contextCallback)));
 }
        public EventMessageFactoryTests()
        {
            eventMetadataProviders = new[]
            {
                Substitute.For <IEventMetadataProvider>(),
                Substitute.For <IEventMetadataProvider>()
            };

            sut = new EventMessageFactory(eventMetadataProviders);
        }
        public void TestGetEventMessage()
        {
            var target = EventMessageFactory.GetEventMessage();

            Assert.Multiple(() =>
            {
                Assert.That(target, Is.Not.Null, "EventMessage must not be null");
                Assert.That(target.EventType, Is.EqualTo(EventType.Undefined));
            });
        }
Exemple #23
0
 public static EventActivityBinder <TInstance, TData> Schedule <TInstance, TData, TMessage>(
     this EventActivityBinder <TInstance, TData> source, Schedule <TInstance, TMessage> schedule,
     EventMessageFactory <TInstance, TData, TMessage> messageFactory,
     Action <SendContext> contextCallback)
     where TInstance : class, SagaStateMachineInstance
     where TData : class
     where TMessage : class
 {
     return(source.Add(new ScheduleActivity <TInstance, TData, TMessage>(messageFactory, schedule, contextCallback, x => schedule.Delay)));
 }
Exemple #24
0
        public Form1()
        {
            InitializeComponent();

            EventMessageFactory factory = new EventMessageFactory();

            factory.CreateSubscription("CriticalEventsMonitor", "0"); // 0 is critical priority per the data generator
            subscription   = factory.CreateSubscriptionClient("CriticalEventsMonitor");
            btnListen.Text = "Don't Listen";
            subscription.StartListener(message => this.UpdateUI(message.GetBody <EventMessage>().Message));
        }
        /// <summary>
        /// Send a request to the configured service endpoint, and setup the state machine to accept the response.
        /// </summary>
        /// <typeparam name="TInstance">The state instance type</typeparam>
        /// <typeparam name="TRequest">The request message type</typeparam>
        /// <typeparam name="TResponse">The response message type</typeparam>
        /// <param name="binder">The event binder</param>
        /// <param name="request">The configured request to use</param>
        /// <param name="messageFactory">The request message factory</param>
        /// <returns></returns>
        public static EventActivityBinder <TInstance> Request <TInstance, TRequest, TResponse>(
            this EventActivityBinder <TInstance> binder, Request <TInstance, TRequest, TResponse> request,
            EventMessageFactory <TInstance, TRequest> messageFactory)
            where TInstance : class, SagaStateMachineInstance
            where TRequest : class
            where TResponse : class
        {
            var activity = new RequestActivity <TInstance, TRequest, TResponse>(request, messageFactory);

            return(binder.Add(activity));
        }
Exemple #26
0
        /// <summary>
        /// Send a request to the configured service endpoint, and setup the state machine to accept the response.
        /// </summary>
        /// <typeparam name="TInstance">The state instance type</typeparam>
        /// <typeparam name="TRequest">The request message type</typeparam>
        /// <typeparam name="TResponse">The response message type</typeparam>
        /// <param name="binder">The event binder</param>
        /// <param name="request">The configured request to use</param>
        /// <param name="serviceAddressProvider"></param>
        /// <param name="messageFactory">The request message factory</param>
        /// <returns></returns>
        public static EventActivityBinder <TInstance> Request <TInstance, TRequest, TResponse>(
            this EventActivityBinder <TInstance> binder, Request <TInstance, TRequest, TResponse> request,
            ServiceAddressProvider <TInstance> serviceAddressProvider, EventMessageFactory <TInstance, TRequest> messageFactory)
            where TInstance : class, SagaStateMachineInstance
            where TRequest : class
            where TResponse : class
        {
            ScheduleTokenId.UseTokenId <RequestTimeoutExpired <TRequest> >(x => x.RequestId);
            var activity = new RequestActivity <TInstance, TRequest, TResponse>(request, serviceAddressProvider, messageFactory);

            return(binder.Add(activity));
        }
        public void TestPublishSuccess()
        {
            var ringBuffer = new RingBuffer <EventMessage>(() => new EventMessage(),
                                                           new SingleProducerSequencer(8, new YieldingWaitStrategy()));

            var target = new Producer(ringBuffer);

            var message = EventMessageFactory.GetEventMessage();

            message.EventType                 = EventType.OrderPlaced;
            message.EventData.Order.Id        = GetOrderId();
            message.EventData.Order.AccountId = 100001L;
            message.EventData.Order.Price     = 100m;

            target.OnData(message);
            Assert.That(ringBuffer.ClaimAndGetPreallocated(0).EventData.Order.Id, Is.EqualTo(message.EventData.Order.Id));
        }
Exemple #28
0
        private static void SendEventMessage()
        {
            var originObject = new UpdatePurchaseOrderStatusByBillIdMqContract()
            {
                UpdatePurchaseOrderStatusType = 1,
                RelationBillType = 10,
                RelationBillId   = 10016779,
                UpdateStatus     = 30,
                ModifiedBy       = 11
            };

            var sendMessage        = EventMessageFactory.CreateEventMessageInstance(originObject, MessageTypeConst.ZgUpdatePurchaseStatus);
            var mqConfigDomFactory = MqConfigDomFactory.CreateConfigDomInstance();

            RabbitMqClient.Instance.TriggerEventMessage(sendMessage, mqConfigDomFactory.MqExchangeName, mqConfigDomFactory.MqListenQueueName);
            Console.WriteLine(11);
        }
        public override void Run()
        {
            // This is a sample worker implementation. Replace with your logic.
            Trace.WriteLine("EventPoint_WorkerRole entry point called", "Information");

            EventMessageFactory factory = new EventMessageFactory();

            factory.CreateSubscription("AllEventsWorkerRole"); // no filter, all events
            subscription = factory.CreateSubscriptionClient("AllEventsWorkerRole");

            // using listener extension methods provided by Microsoft.Samples.ServiceBusMessaging
            subscription.StartListener(message => WriteToAzureTable(message));

            while (true)
            {
                Thread.Sleep(2000);
            }
        }
        public override void Run()
        {
            Trace.WriteLine("CriticalPersister entry point called", "Information");

            EventMessageFactory factory = new EventMessageFactory();

            factory.CreateSubscription("CriticalEventsPersister", "0"); // 0 is critical priority per the data generator
            subscription = factory.CreateSubscriptionClient("CriticalEventsPersister");

            eventService = new CriticalEventService();

            // using listener extension methods provided by Microsoft.Samples.ServiceBusMessaging
            subscription.StartListener(message => Publish(message));

            while (true)
            {
                Thread.Sleep(2000);
            }
        }