コード例 #1
0
        public BoundedContextListener(
            BoundedContextListenerConfiguration configuration,
            IEventConverter eventConverter,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ILogger logger,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IImplementationsOf <IEvent> eventTypes,
            IEventStore eventStore,
            IEventEnvelopes eventEnvelopes,
            IEventSequenceNumbers eventSequenceNumbers,
            IEventSourceVersions eventSourceVersions,
            ICommittedEventStreamBridge committedEventStreamBridge,
            IConsumer consumer)
        {
            _eventConverter = eventConverter;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _eventTypes                 = eventTypes;
            _eventSequenceNumbers       = eventSequenceNumbers;
            _eventStore                 = eventStore;
            _eventEnvelopes             = eventEnvelopes;
            _eventSourceVersions        = eventSourceVersions;
            _committedEventStreamBridge = committedEventStreamBridge;
            _consumer = consumer;

            _serializer    = new JsonSerializer();
            _configuration = configuration;
        }
コード例 #2
0
ファイル: AlertFeedbackService.cs プロジェクト: wegiangb/cbs
 public AlertFeedbackService(ISmsSendingService smsSendingService, IDataCollectors dataCollectors, IMessageTemplateService messageTemplateService, IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
 {
     _smsSendingService = smsSendingService;
     _dataCollectors    = dataCollectors;
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _messageTemplateService            = messageTemplateService;
 }
コード例 #3
0
 public CaseReportPolicy(ICaseReports caseReports, IHealthRisks healthRisks, IAlertFeedbackService feedbackService, IAlerts alerts, IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _caseReports     = caseReports;
     _healthRisks     = healthRisks;
     _feedbackService = feedbackService;
     _alerts          = alerts;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandContextFactory"/> class.
 /// </summary>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinator an <see cref="UncommittedEvents"/>.</param>
 /// <param name="executionContextManager">A <see cref="IExecutionContextManager"/> for getting execution context from.</param>
 /// <param name="logger"><see cref="ILogger"/> to use for logging.</param>
 public CommandContextFactory(
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     IExecutionContextManager executionContextManager,
     ILogger logger)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _executionContextManager           = executionContextManager;
     _logger = logger;
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="CommandContextFactory">CommandContextFactory</see>
 /// </summary>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinator an <see cref="UncommittedEventStream"/></param>
 /// <param name="processMethodInvoker">A <see cref="IProcessMethodInvoker"/> for processing events</param>
 /// <param name="executionContextManager">A <see cref="IExecutionContextManager"/> for getting execution context from</param>
 public CommandContextFactory(
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     IProcessMethodInvoker processMethodInvoker,
     IExecutionContextManager executionContextManager)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _processMethodInvoker    = processMethodInvoker;
     _executionContextManager = executionContextManager;
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new <see cref="CommandContext">CommandContext</see>
 /// </summary>
 /// <param name="command">The <see cref="ICommand">command</see> the context is for</param>
 /// <param name="executionContext">The <see cref="IExecutionContext"/> for the command</param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 /// <param name="uncommittedEventStreamCoordinator">The <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating the committing of events</param>
 public CommandContext(
     ICommand command,
     IExecutionContext executionContext,
     IEventStore eventStore,
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
 {
     Command          = command;
     ExecutionContext = executionContext;
     _eventStore      = eventStore;
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
 }
コード例 #7
0
ファイル: CommandContext.cs プロジェクト: ProCoSys/Bifrost
 /// <summary>
 /// Initializes a new <see cref="CommandContext">CommandContext</see>
 /// </summary>
 /// <param name="command">The <see cref="ICommand">command</see> the context is for</param>
 /// <param name="executionContext">The <see cref="IExecutionContext"/> for the command</param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 /// <param name="uncommittedEventStreamCoordinator">The <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating the committing of events</param>
 public CommandContext(
     ICommand command,
     IExecutionContext executionContext,
     IEventStore eventStore,
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
 {
     Command = command;
     ExecutionContext = executionContext;
     _eventStore = eventStore;
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
 }
コード例 #8
0
ファイル: CommandContext.cs プロジェクト: svethors/DotNET.SDK
        /// <summary>
        /// Initializes a new <see cref="CommandContext">CommandContext</see>
        /// </summary>
        /// <param name="command">The <see cref="CommandRequest">command</see> the context is for</param>
        /// <param name="executionContext">The <see cref="IExecutionContext"/> for the command</param>
        /// <param name="uncommittedEventStreamCoordinator">The <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating the committing of events</param>
        public CommandContext(
            CommandRequest command,
            IExecutionContext executionContext,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
        {
            Command          = command;
            ExecutionContext = executionContext;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;

            // This should be exposed to the client somehow - maybe even coming from the client
            TransactionCorrelationId = Guid.NewGuid();
        }
コード例 #9
0
 /// <summary>
 /// Initializes a new instance of <see cref="CommandContextFactory">CommandContextFactory</see>
 /// </summary>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinator an <see cref="UncommittedEventStream"/></param>
 /// <param name="sagaLibrarian">A <see cref="ISagaLibrarian"/> for saving sagas to</param>
 /// <param name="processMethodInvoker">A <see cref="IProcessMethodInvoker"/> for processing events</param>
 /// <param name="executionContextManager">A <see cref="IExecutionContextManager"/> for getting execution context from</param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 public CommandContextFactory(
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     ISagaLibrarian sagaLibrarian,
     IProcessMethodInvoker processMethodInvoker,
     IExecutionContextManager executionContextManager,
     IEventStore eventStore)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _sagaLibrarian = sagaLibrarian;
     _processMethodInvoker = processMethodInvoker;
     _eventStore = eventStore;
     _executionContextManager = executionContextManager;
 }
コード例 #10
0
 /// <summary>
 /// Initializes a new instance of <see cref="CommandContextFactory">CommandContextFactory</see>
 /// </summary>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinator an <see cref="UncommittedEventStream"/></param>
 /// <param name="sagaLibrarian">A <see cref="ISagaLibrarian"/> for saving sagas to</param>
 /// <param name="processMethodInvoker">A <see cref="IProcessMethodInvoker"/> for processing events</param>
 /// <param name="executionContextManager">A <see cref="IExecutionContextManager"/> for getting execution context from</param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 public CommandContextFactory(
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     ISagaLibrarian sagaLibrarian,
     IProcessMethodInvoker processMethodInvoker,
     IExecutionContextManager executionContextManager,
     IEventStore eventStore)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _sagaLibrarian           = sagaLibrarian;
     _processMethodInvoker    = processMethodInvoker;
     _eventStore              = eventStore;
     _executionContextManager = executionContextManager;
 }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommandContext"/> class.
        /// </summary>
        /// <param name="command">The <see cref="CommandRequest">command</see> the context is for.</param>
        /// <param name="executionContext">The <see cref="ExecutionContext"/> for the command.</param>
        /// <param name="uncommittedEventStreamCoordinator">The <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating the committing of events.</param>
        /// <param name="logger"><see cref="ILogger"/> to use for logging.</param>
        public CommandContext(
            CommandRequest command,
            ExecutionContext executionContext,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ILogger logger)
        {
            Command          = command;
            ExecutionContext = executionContext;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;

            CorrelationId = CorrelationId.New();
        }
コード例 #12
0
ファイル: CommandContext.cs プロジェクト: woksin/Runtime
        /// <summary>
        /// Initializes a new <see cref="CommandContext">CommandContext</see>
        /// </summary>
        /// <param name="command">The <see cref="CommandRequest">command</see> the context is for</param>
        /// <param name="executionContext">The <see cref="ExecutionContext"/> for the command</param>
        /// <param name="uncommittedEventStreamCoordinator">The <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating the committing of events</param>
        /// <param name="logger"><see cref="ILogger"/> to use for logging</param>
        public CommandContext(
            CommandRequest command,
            ExecutionContext executionContext,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ILogger logger)
        {
            Command          = command;
            ExecutionContext = executionContext;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;

            // This should be exposed to the client somehow - maybe even coming from the client
            CorrelationId = CorrelationId.New();
        }
コード例 #13
0
ファイル: SagaCommandContext.cs プロジェクト: JoB70/Bifrost
 /// <summary>
 /// Initializes an instance of the <see cref="SagaCommandContext"/> for a saga
 /// </summary>
 /// <param name="saga"><see cref="ISaga"/> to start the context for</param>
 /// <param name="command"><see cref="ICommand"/> that will be applied </param>
 /// <param name="executionContext">A <see cref="IExecutionContext"/> that is the context of execution for the <see cref="ICommand"/></param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating a <see cref="UncommittedEventStream"/></param>
 /// <param name="processMethodInvoker">A <see cref="IProcessMethodInvoker"/> for processing events on the <see cref="ISaga"/></param>
 /// <param name="sagaLibrarian">A <see cref="ISagaLibrarian"/> for dealing with the <see cref="ISaga"/> and persistence</param>
 public SagaCommandContext(
     ISaga saga,
     ICommand command,
     IExecutionContext executionContext,
     IEventStore eventStore,
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     IProcessMethodInvoker processMethodInvoker,
     ISagaLibrarian sagaLibrarian)
 {
     Command = command;
     ExecutionContext = executionContext;
     _saga = saga;
     _eventStore = eventStore;
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _processMethodInvoker = processMethodInvoker;
     _sagaLibrarian = sagaLibrarian;
 }
コード例 #14
0
ファイル: SagaCommandContext.cs プロジェクト: csuffyy/Bifrost
 /// <summary>
 /// Initializes an instance of the <see cref="SagaCommandContext"/> for a saga
 /// </summary>
 /// <param name="saga"><see cref="ISaga"/> to start the context for</param>
 /// <param name="command"><see cref="ICommand"/> that will be applied </param>
 /// <param name="executionContext">A <see cref="IExecutionContext"/> that is the context of execution for the <see cref="ICommand"/></param>
 /// <param name="eventStore">A <see cref="IEventStore"/> that will receive any events generated</param>
 /// <param name="uncommittedEventStreamCoordinator">A <see cref="IUncommittedEventStreamCoordinator"/> to use for coordinating a <see cref="UncommittedEventStream"/></param>
 /// <param name="processMethodInvoker">A <see cref="IProcessMethodInvoker"/> for processing events on the <see cref="ISaga"/></param>
 /// <param name="sagaLibrarian">A <see cref="ISagaLibrarian"/> for dealing with the <see cref="ISaga"/> and persistence</param>
 public SagaCommandContext(
     ISaga saga,
     ICommand command,
     IExecutionContext executionContext,
     IEventStore eventStore,
     IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
     IProcessMethodInvoker processMethodInvoker,
     ISagaLibrarian sagaLibrarian)
 {
     Command          = command;
     ExecutionContext = executionContext;
     _saga            = saga;
     _eventStore      = eventStore;
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _processMethodInvoker = processMethodInvoker;
     _sagaLibrarian        = sagaLibrarian;
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of <see cref="EventEmitter"/>
 /// </summary>
 public BaseController()
 {
     _uncommittedEventStreamCoordinator = Internals.ServiceProvider.GetService(typeof(IUncommittedEventStreamCoordinator)) as IUncommittedEventStreamCoordinator;
 }
コード例 #16
0
        public BoundedContextListener(
            KafkaConnectionString connectionString,
            ListenerConfiguration configuration,
            IEventConverter eventConverter,
            IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator,
            ISerializer serializer,
            ILogger logger,
            IApplicationResourceIdentifierConverter applicationResourceIdentifierConverter,
            IImplementationsOf <IEvent> eventTypes,
            IEventStore eventStore,
            IEventEnvelopes eventEnvelopes,
            IEventSequenceNumbers eventSequenceNumbers,
            IEventSourceVersions eventSourceVersions,
            ICommittedEventStreamBridge committedEventStreamBridge)
        {
            _serializer     = serializer;
            _eventConverter = eventConverter;
            _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
            _logger = logger;
            _applicationResourceIdentifierConverter = applicationResourceIdentifierConverter;
            _eventTypes                 = eventTypes;
            _eventSequenceNumbers       = eventSequenceNumbers;
            _eventStore                 = eventStore;
            _eventEnvelopes             = eventEnvelopes;
            _eventSourceVersions        = eventSourceVersions;
            _committedEventStreamBridge = committedEventStreamBridge;



            logger.Information($"Listening on topic '{configuration.Topic}' from '{connectionString}'");

            var config = new Dictionary <string, object>
            {
                { "bootstrap.servers", connectionString },
                { "group.id", "simple-consumer" },
                { "enable.auto.commit", true },
                { "auto.commit.interval.ms", 1000 },
                {
                    "default.topic.config",
                    new Dictionary <string, object>()
                    {
                        { "auto.offset.reset", "smallest" }
                    }
                }
            };

            _consumer = new Consumer <Ignore, string>(config, null, new StringDeserializer(Encoding.UTF8));
            _consumer.Assign(new [] { new TopicPartition(configuration.Topic, 0) });
            _consumer.OnMessage += (_, msg) =>
            {
                try
                {
                    logger.Trace($"Message received '{msg.Value}'");
                    var raw = _serializer.FromJson <dynamic[]>(msg.Value);

                    foreach (var rawContentAndEnvelope in raw)
                    {
                        var eventSourceId   = (EventSourceId)Guid.Parse(rawContentAndEnvelope.Content.EventSourceId.ToString());
                        var eventIdentifier = _applicationResourceIdentifierConverter.FromString(rawContentAndEnvelope.Envelope.Event.ToString());
                        var version         = EventSourceVersion.FromCombined((double)rawContentAndEnvelope.Envelope.Version);
                        var correlationId   = (TransactionCorrelationId)Guid.Parse(rawContentAndEnvelope.Envelope.CorrelationId.ToString());
                        CorrelationId = correlationId;

                        _logger.Trace($"Received event of with resource name '{eventIdentifier.Resource.Name}' from '{eventSourceId}' with version '{version}' in correlation '{correlationId}'");
                        var eventType = _eventTypes.SingleOrDefault(et => et.Name == eventIdentifier.Resource.Name);
                        if (eventType != null)
                        {
                            _logger.Trace("Matching Event Type : " + eventType.AssemblyQualifiedName);
                            var @event = Activator.CreateInstance(eventType, eventSourceId) as IEvent;
                            _serializer.FromJson(@event, rawContentAndEnvelope.Content.ToString());

                            var eventSource            = new ExternalSource(eventSourceId);
                            var uncommittedEventStream = new UncommittedEventStream(eventSource);
                            uncommittedEventStream.Append(@event, version);


                            _logger.Information($"Committing uncommitted event stream with correlationId '{correlationId}'");
                            var envelopes        = _eventEnvelopes.CreateFrom(eventSource, uncommittedEventStream.EventsAndVersion);
                            var envelopesAsArray = envelopes.ToArray();
                            var eventsAsArray    = uncommittedEventStream.ToArray();

                            _logger.Trace("Create an array of events and envelopes");
                            var eventsAndEnvelopes = new List <EventAndEnvelope>();
                            for (var eventIndex = 0; eventIndex < eventsAsArray.Length; eventIndex++)
                            {
                                var envelope     = envelopesAsArray[eventIndex];
                                var currentEvent = eventsAsArray[eventIndex];
                                eventsAndEnvelopes.Add(new EventAndEnvelope(
                                                           envelope
                                                           .WithTransactionCorrelationId(correlationId)
                                                           .WithSequenceNumber(_eventSequenceNumbers.Next())
                                                           .WithSequenceNumberForEventType(_eventSequenceNumbers.NextForType(envelope.Event)),
                                                           currentEvent
                                                           ));
                            }

                            _logger.Trace("Committing events to event store");
                            _eventStore.Commit(eventsAndEnvelopes);

                            _logger.Trace($"Set event source versions for the event source '{envelopesAsArray[0].EventSource}' with id '{envelopesAsArray[0].EventSourceId}'");
                            _eventSourceVersions.SetFor(envelopesAsArray[0].EventSource, envelopesAsArray[0].EventSourceId, envelopesAsArray[envelopesAsArray.Length - 1].Version);

                            _logger.Trace("Create a committed event stream");
                            var committedEventStream = new CommittedEventStream(uncommittedEventStream.EventSourceId, eventsAndEnvelopes);
                            _committedEventStreamBridge.Send(committedEventStream);

                            CorrelationId = Guid.Empty;
                        }
                    }
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, "Error during receiving");
                }
            };
        }
コード例 #17
0
ファイル: EventsController.cs プロジェクト: tristanpfost/cbs
 public EventsController(ITypeFinder typeFinder,
                         IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _typeFinder = typeFinder;
 }
コード例 #18
0
ファイル: EventReplayer.cs プロジェクト: twedler/cbs
 public EventReplayer(IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator, IExecutionContextManager executionContextManager, ILogger logger)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _executionContextManager           = executionContextManager;
     _logger = logger;
 }
コード例 #19
0
 public EventReplayer(IUncommittedEventStreamCoordinator uncommittedEventStreamCoordinator, ILogger logger)
 {
     _uncommittedEventStreamCoordinator = uncommittedEventStreamCoordinator;
     _logger = logger;
 }