public INeedARequestContext TaskQueues(MessagingConfiguration configuration) { messageStore = configuration.MessageStore; messagingGateway = configuration.MessagingGateway; messageMapperRegistry = configuration.MessageMapperRegistry; return this; }
public void Repost(List<string> messageIds, IAmAMessageStore<Message> messageStore, IAmAMessageProducer messageProducer) { var foundMessages = GetMessagesFromStore(messageStore, messageIds); foreach (var foundMessage in foundMessages) { messageProducer.Send(foundMessage); } }
public MessageStoreViewerModel(IAmAMessageStore<Message> connectedStore, MessageStoreActivationState foundState) { Name = foundState.Name; StoreType = foundState.StoreType; TypeName = foundState.TypeName; ConnectionString = foundState.ConnectionString; TableName = foundState.TableName; //TODO: ++ double something with connectedStore }
public MessagingConfiguration( IAmAMessageStore<Message> messageStore, IAmAMessagingGateway messagingGateway, IAmAMessageMapperRegistry messageMapperRegistry ) { MessageStore = messageStore; MessagingGateway = messagingGateway; MessageMapperRegistry = messageMapperRegistry; }
/// <summary> /// Creates the specified configuration. /// </summary> /// <param name="gateway">The gateway to the control bus to send messages</param> /// <param name="logger">The logger to use</param> /// <param name="messageStore">The message store for outgoing messages to the control bus</param> /// <returns>IAmAControlBusSender.</returns> public IAmAControlBusSender Create(IAmAMessageStore<Message> messageStore, IAmAMessageProducer gateway) { var mapper = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MonitorEventMessageMapper())); mapper.Register<MonitorEvent, MonitorEventMessageMapper>(); return new ControlBusSender(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration()) .DefaultPolicy() .TaskQueues(new MessagingConfiguration(messageStore, gateway, mapper)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() ); }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> /// <param name="messageGatewaySendTimeout">How long should we wait to post to the message store</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, int messageStoreTimeout = 300, int messageGatewaySendTimeout = 300 ) : this(subscriberRegistry, handlerFactory, requestContextFactory, policyRegistry, mapperRegistry, messageStore, messageProducer, LogProvider.GetCurrentClassLogger()) { }
/// <summary> /// Gets the selected messages from the store /// </summary> /// <param name="messageStore">The store to retrieve from</param> /// <param name="messageIds">The messages to retrieve</param> /// <returns></returns> private static IEnumerable<Message> GetMessagesFromStore(IAmAMessageStore<Message> messageStore, IReadOnlyCollection<string> messageIds) { IEnumerable<Message> foundMessages = messageIds .Select(messageId => messageStore.Get(Guid.Parse(messageId))) .Where(fm => fm != null) .ToList(); if (foundMessages.Count() < messageIds.Count) { throw new SystemException("Cannot find messages " + string.Join(",", messageIds.Where(id => foundMessages.All(fm => fm.Id.ToString() != id.ToString())).ToArray())); } return foundMessages; }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="messageStoreWriteTimeout">How long to wait when writing to the message store</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> public MessagingConfiguration( IAmAMessageStore<Message> messageStore, IAmAMessageProducer messageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int messageStoreWriteTimeout = 300, int messagingGatewaySendTimeout = 300 ) { MessageStore = messageStore; MessageProducer = messageProducer; MessageMapperRegistry = messageMapperRegistry; MessageStoreWriteTimeout = messageStoreWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="messageStoreWriteTimeout">How long to wait when writing to the message store</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> public MessagingConfiguration( IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int messageStoreWriteTimeout = 300, int messagingGatewaySendTimeout = 300 ) { MessageStore = messageStore; MessageProducer = messageProducer; MessageMapperRegistry = messageMapperRegistry; MessageStoreWriteTimeout = messageStoreWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; }
/// <summary> /// Gets the selected messages from the store /// </summary> /// <param name="messageStore">The store to retrieve from</param> /// <param name="messageIds">The messages to retrieve</param> /// <returns></returns> private static IEnumerable <Message> GetMessagesFromStore(IAmAMessageStore <Message> messageStore, IReadOnlyCollection <string> messageIds) { IEnumerable <Message> foundMessages = messageIds .Select(messageId => messageStore.Get(Guid.Parse(messageId))) .Where(fm => fm != null) .ToList(); if (foundMessages.Count() < messageIds.Count) { throw new IndexOutOfRangeException("Cannot find messages " + string.Join(",", messageIds.Where(id => foundMessages.All(fm => fm.Id.ToString() != id.ToString())).ToArray())); } return(foundMessages); }
/// <summary> /// The <see cref="CommandProcessor"/> wants to support <see cref="CommandProcessor.Call{T}(T)"/> using RPC between client and server /// </summary> /// <param name="messagingConfiguration"></param> /// <returns></returns> public INeedARequestContext RequestReplyQueues(MessagingConfiguration configuration) { _useRequestReplyQueues = true; _messageStore = configuration.MessageStore; _asyncMessageStore = configuration.AsyncMessageStore; _messagingGateway = configuration.MessageProducer; _asyncMessagingGateway = configuration.AsyncMessageProducer; _messageMapperRegistry = configuration.MessageMapperRegistry; _messageStoreWriteTimeout = configuration.MessageStoreWriteTimeout; _messagingGatewaySendTimeout = configuration.MessagingGatewaySendTimeout; _responseChannelFactory = configuration.ResponseChannelFactory; return(this); }
/// <summary> /// Creates the specified configuration. /// </summary> /// <param name="gateway">The gateway to the control bus to send messages</param> /// <param name="logger">The logger to use</param> /// <param name="messageStore">The message store for outgoing messages to the control bus</param> /// <returns>IAmAControlBusSender.</returns> public IAmAControlBusSender Create(IAmAMessageStore <Message> messageStore, IAmAMessageProducer gateway) { var mapper = new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MonitorEventMessageMapper())); mapper.Register <MonitorEvent, MonitorEventMessageMapper>(); return(new ControlBusSender(CommandProcessorBuilder.With() .Handlers(new HandlerConfiguration()) .DefaultPolicy() .TaskQueues(new MessagingConfiguration(messageStore, gateway, mapper)) .RequestContextFactory(new InMemoryRequestContextFactory()) .Build() )); }
private IAmAMessageStore <Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult <MessageStoreViewerModel, MessageStoreViewerModelError> errorResult) { IAmAMessageStore <Message> foundStore = _storeViewerFactory.Connect(storeName); if (foundStore == null) { { errorResult = new ViewModelRetrieverResult <MessageStoreViewerModel, MessageStoreViewerModelError>( MessageStoreViewerModelError.StoreNotFound); return(null); } } errorResult = null; return(foundStore); }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when only task queue support is required /// </summary> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messagingGateway">The messaging gateway.</param> /// <param name="logger">The logger.</param> public CommandProcessor( IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messagingGateway, ILog logger) { this.requestContextFactory = requestContextFactory; this.policyRegistry = policyRegistry; this.logger = logger; this.mapperRegistry = mapperRegistry; this.messageStore = messageStore; this.messagingGateway = messagingGateway; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messagingGateway">The messaging gateway.</param> /// <param name="logger">The logger.</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messagingGateway, ILog logger) : this(subscriberRegistry, handlerFactory, requestContextFactory, policyRegistry, logger) { this.mapperRegistry = mapperRegistry; this.messageStore = messageStore; this.messagingGateway = messagingGateway; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when only task queue support is required /// </summary> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> public CommandProcessor( IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, int messageStoreTimeout = 300) { _requestContextFactory = requestContextFactory; _policyRegistry = policyRegistry; _messageStoreTimeout = messageStoreTimeout; _mapperRegistry = mapperRegistry; _messageStore = messageStore; _messageProducer = messageProducer; }
/// <summary> /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class. /// </summary> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageMapperRegistry">The message mapper registry.</param> /// <param name="messageStoreWriteTimeout">How long to wait when writing to the message store</param> /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param> public MessagingConfiguration( IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, IAmAMessageMapperRegistry messageMapperRegistry, int messageStoreWriteTimeout = 300, int messagingGatewaySendTimeout = 300, IAmAChannelFactory responseChannelFactory = null ) { MessageStore = messageStore; MessageProducer = messageProducer; MessageMapperRegistry = messageMapperRegistry; MessageStoreWriteTimeout = messageStoreWriteTimeout; MessagingGatewaySendTimeout = messagingGatewaySendTimeout; ResponseChannelFactory = responseChannelFactory; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, int messageStoreTimeout = 300) : this(subscriberRegistry, handlerFactory, requestContextFactory, policyRegistry) { _mapperRegistry = mapperRegistry; _messageStore = messageStore; _messageProducer = messageProducer; _messageStoreTimeout = messageStoreTimeout; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when only task queue support is required /// </summary> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> /// <param name="featureSwitchRegistry">The feature switch config provider.</param> public CommandProcessor( IAmARequestContextFactory requestContextFactory, IPolicyRegistry <string> policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer, int messageStoreTimeout = 300, IAmAFeatureSwitchRegistry featureSwitchRegistry = null) { _requestContextFactory = requestContextFactory; _policyRegistry = policyRegistry; _messageStoreTimeout = messageStoreTimeout; _mapperRegistry = mapperRegistry; _messageStore = messageStore; _messageProducer = messageProducer; _featureSwitchRegistry = featureSwitchRegistry; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required, and you want to inject a test logger /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="asyncHandlerFactory">The async handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="asyncMessageStore">The message store supporting async/await.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageStoreAsync <Message> asyncMessageStore, IAmAMessageProducer messageProducer, IAmAMessageProducerAsync asyncMessageProducer, int messageStoreTimeout = 300 ) : this( subscriberRegistry, handlerFactory, asyncHandlerFactory, requestContextFactory, policyRegistry, mapperRegistry, messageStore, asyncMessageStore, messageProducer, asyncMessageProducer, LogProvider.For <CommandProcessor>(), messageStoreTimeout) { }
private IAmAMessageStoreViewer <Message> GetStoreViewer(string storeName, out ViewModelRetrieverResult <MessageListModel, MessageListModelError> errorResult) { IAmAMessageStore <Message> foundStore = _messageStoreViewerFactory.Connect(storeName); if (foundStore == null) { errorResult = new ViewModelRetrieverResult <MessageListModel, MessageListModelError>(MessageListModelError.StoreNotFound); return(null); } var foundViewer = foundStore as IAmAMessageStoreViewer <Message>; if (foundViewer == null) { errorResult = new ViewModelRetrieverResult <MessageListModel, MessageListModelError>(MessageListModelError.StoreMessageViewerNotImplemented); return(null); } errorResult = null; return(foundViewer); }
protected virtual void Dispose(bool disposing) { if (_disposed) { return; } if (disposing) { if (_messageProducer != null) { _messageProducer.Dispose(); } } _messageStore = null; _messageProducer = null; _disposed = true; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required, and you want to inject a test logger /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="asyncHandlerFactory">The async handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="asyncMessageStore">The message store supporting async/await.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> /// <param name="featureSwitchRegistry">The feature switch config provider.</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageStoreAsync <Message> asyncMessageStore, IAmAMessageProducer messageProducer, IAmAMessageProducerAsync asyncMessageProducer, int messageStoreTimeout = 300, IAmAFeatureSwitchRegistry featureSwitchRegistry = null) : this(subscriberRegistry, handlerFactory, asyncHandlerFactory, requestContextFactory, policyRegistry, featureSwitchRegistry) { _mapperRegistry = mapperRegistry; _messageStore = messageStore; _asyncMessageStore = asyncMessageStore; _messageProducer = messageProducer; _asyncMessageProducer = asyncMessageProducer; _messageStoreTimeout = messageStoreTimeout; }
/// <summary> /// Initializes a new instance of the <see cref="CommandProcessor"/> class. /// Use this constructor when both task queue and command processor support is required, and you want to inject a test logger /// </summary> /// <param name="subscriberRegistry">The subscriber registry.</param> /// <param name="handlerFactory">The handler factory.</param> /// <param name="asyncHandlerFactory">The async handler factory.</param> /// <param name="requestContextFactory">The request context factory.</param> /// <param name="policyRegistry">The policy registry.</param> /// <param name="mapperRegistry">The mapper registry.</param> /// <param name="messageStore">The message store.</param> /// <param name="asyncMessageStore">The message store supporting async/await.</param> /// <param name="messageProducer">The messaging gateway.</param> /// <param name="asyncMessageProducer">The messaging gateway supporting async/await.</param> /// <param name="logger">The logger.</param> /// <param name="messageStoreTimeout">How long should we wait to write to the message store</param> /// <param name="messageGatewaySendTimeout">How long should we wait to post to the message store</param> public CommandProcessor( IAmASubscriberRegistry subscriberRegistry, IAmAHandlerFactory handlerFactory, IAmAHandlerFactoryAsync asyncHandlerFactory, IAmARequestContextFactory requestContextFactory, IAmAPolicyRegistry policyRegistry, IAmAMessageMapperRegistry mapperRegistry, IAmAMessageStore <Message> messageStore, IAmAMessageStoreAsync <Message> asyncMessageStore, IAmAMessageProducer messageProducer, IAmAMessageProducerAsync asyncMessageProducer, ILog logger, int messageStoreTimeout = 300, int messageGatewaySendTimeout = 300 ) : this(subscriberRegistry, handlerFactory, asyncHandlerFactory, requestContextFactory, policyRegistry, logger) { _mapperRegistry = mapperRegistry; _messageStore = messageStore; _asyncMessageStore = asyncMessageStore; _messageProducer = messageProducer; _asyncMessageProducer = asyncMessageProducer; _messageStoreTimeout = messageStoreTimeout; }
public FakeMessageStoreViewerFactory(IAmAMessageStore <Message> fakeStore, string storeName) { _fakeStore = fakeStore; this.storeName = storeName; }
public BrighterMessaging(IAmAMessageStore <Message> messageStore, IAmAMessageProducer producer) { MessageStore = messageStore; Producer = producer; }
public FakeMessageStoreViewerFactory(IAmAMessageStore<Message> fakeStore, string storeName) { _fakeStore = fakeStore; this.storeName = storeName; }
/// <summary> /// The <see cref="CommandProcessor"/> wants to support <see cref="CommandProcessor.Post{T}(T)"/> or <see cref="CommandProcessor.Repost"/> using Task Queues. /// You need to provide a policy to specify how QoS issues, specifically <see cref="CommandProcessor.RETRYPOLICY "/> or <see cref="CommandProcessor.CIRCUITBREAKER "/> /// are handled by adding appropriate <see cref="Policies"/> when choosing this option. /// /// </summary> /// <param name="configuration">The Task Queues configuration.</param> /// <returns>INeedARequestContext.</returns> public INeedARequestContext TaskQueues(MessagingConfiguration configuration) { _useTaskQueues = true; _messageStore = configuration.MessageStore; _messagingGateway = configuration.MessagingGateway; _messageMapperRegistry = configuration.MessageMapperRegistry; _messageStoreWriteTimeout = configuration.MessageStoreWriteTimeout; _messagingGatewaySendTimeout = configuration.MessagingGatewaySendTimeout; return this; }