Exemplo n.º 1
0
        public static Configuration UseCommandBus(this Configuration configuration, string consumerId, string replyTopic = "replyTopic", string replySubscription = "replySubscription", ILinearCommandManager linerCommandManager = null)
        {
            var container = IoCFactory.Instance.CurrentContainer;

            if (linerCommandManager == null)
            {
                linerCommandManager = new LinearCommandManager();
            }
            var messageQueueClient = IoCFactory.Resolve <IMessageQueueClient>();
            var commandBus         = new CommandBus(messageQueueClient, linerCommandManager, consumerId, replyTopic, replySubscription);

            container.RegisterInstance <ICommandBus>(commandBus);
            return(configuration);
        }
Exemplo n.º 2
0
        public Task Send(ICommand command, CancellationToken cancellationToken)
        {
            var currentMessageContext = PerMessageContextLifetimeManager.CurrentMessageContext;

            if (currentMessageContext != null && currentMessageContext.Message is ICommand)
            {
                // A command sent in a CommandContext is not allowed. We throw exception!!!
                throw new NotSupportedException("Command is not allowd to be sent in another command context!");
            }

            string commandKey = null;

            if (command is ILinearCommand)
            {
                var linearKey = LinearCommandManager.GetLinearKey(command as ILinearCommand);
                if (linearKey != null)
                {
                    commandKey = linearKey.ToString();
                }
            }
            IMessageContext commandContext = null;

            commandContext = new MessageContext(CommandTopic, command, ReplyTopic, commandKey);
            Task task = null;

            if (InProc && currentMessageContext == null && !(command is ILinearCommand))
            {
                task = SendInProc(commandContext, cancellationToken);
            }
            else
            {
                if (currentMessageContext != null)
                {
                    ((MessageContext)currentMessageContext).ToBeSentMessageContexts.Add(commandContext);
                }
                else
                {
                    task = SendAsync(commandContext, cancellationToken);
                }
            }
            return(task);
        }
Exemplo n.º 3
0
        public static Configuration UseCommandBus(this Configuration configuration,
                                                  string consumerId,
                                                  string replyTopic        = "replyTopic",
                                                  string replySubscription = "replySubscription",
                                                  ILinearCommandManager linerCommandManager = null,
                                                  ConsumerConfig consumerConfig             = null)
        {
            var builder = ObjectProviderFactory.Instance.ObjectProviderBuilder;

            builder.Register <ICommandBus>(provider =>
            {
                if (linerCommandManager == null)
                {
                    linerCommandManager = new LinearCommandManager();
                }
                var messageQueueClient = provider.GetService <IMessageQueueClient>();
                var commandBus         = new CommandBus(messageQueueClient, linerCommandManager, consumerId, replyTopic,
                                                        replySubscription, consumerConfig);
                return(commandBus);
            }, ServiceLifetime.Singleton);
            return(configuration);
        }
Exemplo n.º 4
0
        public void Add(ICommand command)
        {
            var currentMessageContext = PerMessageContextLifetimeManager.CurrentMessageContext;

            if (currentMessageContext == null)
            {
                throw new CurrentMessageContextIsNull();
            }
            string commandKey = null;

            if (command is ILinearCommand)
            {
                var linearKey = LinearCommandManager.GetLinearKey(command as ILinearCommand);
                if (linearKey != null)
                {
                    commandKey = linearKey.ToString();
                }
            }
            IMessageContext commandContext = new MessageContext(ReplyTopic, command, commandKey);

            ((MessageContext)currentMessageContext).ToBeSentMessageContexts.Add(commandContext);
        }