Exemple #1
0
        /// <summary>
        /// Registers a management endpoint on the bus, which can be used to control
        /// filters and other management control points on the bus.
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host">The host where the endpoint is to be created</param>
        /// <param name="configure">Configure additional values of the underlying receive endpoint</param>
        /// <returns></returns>
        public static IManagementEndpointConfigurator ManagementEndpoint(this IAmazonSqsBusFactoryConfigurator configurator,
                                                                         IAmazonSqsHost host, Action <IAmazonSqsReceiveEndpointConfigurator> configure = null)
        {
            if (configurator == null)
            {
                throw new ArgumentNullException(nameof(configurator));
            }

            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            var queueName = host.Topology.CreateTemporaryQueueName("manage-");

            IAmazonSqsReceiveEndpointConfigurator specification = null;

            configurator.ReceiveEndpoint(host, queueName, x =>
            {
                x.AutoDelete = true;
                x.Durable    = false;

                configure?.Invoke(x);

                specification = x;
            });

            var managementEndpointConfigurator = new ManagementEndpointConfigurator(specification);

            return(managementEndpointConfigurator);
        }
        public AmazonSqsModelContext(ConnectionContext connectionContext, IAmazonSQS amazonSqs, IAmazonSimpleNotificationService amazonSns, IAmazonSqsHost host, CancellationToken cancellationToken)
            : base(new PayloadCacheScope(connectionContext), cancellationToken)
        {
            _connectionContext = connectionContext;
            _amazonSqs         = amazonSqs;
            _amazonSns         = amazonSns;
            _host = host;

            _taskScheduler = new LimitedConcurrencyLevelTaskScheduler(1);
        }
        public SqsReceiveTransport(IAmazonSqsHost host, ReceiveSettings settings, IPipe <ConnectionContext> connectionPipe,
                                   SqsReceiveEndpointContext receiveEndpointContext)
        {
            _host     = host;
            _settings = settings;
            _receiveEndpointContext = receiveEndpointContext;
            _connectionPipe         = connectionPipe;

            _inputAddress = receiveEndpointContext.InputAddress;
        }
        public AmazonSqsReceiveTransport(IAmazonSqsHost host, ReceiveSettings settings, IPipe <ConnectionContext> connectionPipe,
                                         AmazonSqsReceiveEndpointContext context, ReceiveObservable receiveObservable, ReceiveTransportObservable receiveTransportObservable)
        {
            _host           = host;
            _settings       = settings;
            _context        = context;
            _connectionPipe = connectionPipe;

            _receiveObservable          = receiveObservable;
            _receiveTransportObservable = receiveTransportObservable;

            _inputAddress = context.InputAddress;
        }
        public async Task Should_succeed_and_connect_when_properly_configured()
        {
            TaskCompletionSource <bool> received = new TaskCompletionSource <bool>();

            IAmazonSqsHost host = null;

            var busControl = Bus.Factory.CreateUsingAmazonSqs(cfg =>
            {
                host = cfg.Host("us-east-2", h =>
                {
                    h.AccessKey(AwsAccessKey);
                    h.SecretKey(AwsSecretKey);
                });

                cfg.ReceiveEndpoint(host, "input-queue", x =>
                {
                    x.Handler <PingMessage>(async context =>
                    {
                        await context.Publish(new PongMessage(context.Message.CorrelationId));
                    });
                });

                cfg.ReceiveEndpoint(host, "input-queue-too", x =>
                {
                    x.Handler <PongMessage>(async context =>
                    {
                        received.TrySetResult(true);

                        await Util.TaskUtil.Completed;
                    });
                });
            });

            await busControl.StartAsync();

            try
            {
                await busControl.Publish(new PingMessage());

                await received.Task.OrTimeout(TimeSpan.FromSeconds(30));
            }
            finally
            {
                await busControl.StopAsync();
            }
        }
Exemple #6
0
        public async Task Should_succeed_and_connect_when_properly_configured()
        {
            TaskCompletionSource <bool> received = new TaskCompletionSource <bool>();

            IAmazonSqsHost host = null;

            var busControl = Bus.Factory.CreateUsingAmazonSqs(cfg =>
            {
                host = cfg.Host("ap-southeast-2", h =>
                {
                    h.AccessKey(AwsAccessKey);
                    h.SecretKey(AwsSecretKey);
                });

                cfg.ReceiveEndpoint(host, "input-queue", x =>
                {
                    x.Handler <PingMessage>(async context =>
                    {
                        await context.Publish(new PongMessage(context.Message.CorrelationId));
                    });
                });

                cfg.ReceiveEndpoint(host, "input-queue-too", x =>
                {
                    x.Handler <PongMessage>(async context =>
                    {
                        received.TrySetResult(true);

                        await Util.TaskUtil.Completed;
                    });
                });
            });

            await busControl.StartAsync();

            var sendAddress = host.Topology.GetDestinationAddress(typeof(PingMessage));

            var sendEndpoint = await busControl.GetSendEndpoint(sendAddress);

            await sendEndpoint.Send(new PingMessage());

            await received.Task.UntilCompletedOrTimeout(TimeSpan.FromSeconds(120));

            await busControl.StopAsync();
        }
 public bool TryGetHost(IAmazonSqsHost host, out IAmazonSqsHostConfiguration hostConfiguration)
 {
     return(_hosts.TryGetHost(host, out hostConfiguration));
 }
Exemple #8
0
 protected virtual void ConfigureAmazonSqsBusHost(IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host)
 {
 }
 public ReceiveModelFilter(IPipe <ModelContext> pipe, IAmazonSqsHost host)
 {
     _pipe = pipe;
     _host = host;
 }
 public ModelContextFactory(IConnectionCache connectionCache, IAmazonSqsHost host)
 {
     _connectionCache = connectionCache;
     _host            = host;
 }
        public async Task Should_create_queue_with_multiple_subscriptions()
        {
            var messageTypes = new[]
            {
                typeof(Message0), typeof(Message1), typeof(Message2), typeof(Message3), typeof(Message4), typeof(Message5), typeof(Message6),
                typeof(Message7), typeof(Message8), typeof(Message9), typeof(Message10), typeof(Message11), typeof(Message12), typeof(Message13),
                typeof(Message14), typeof(Message15), typeof(Message16), typeof(Message17), typeof(Message18), typeof(Message19), typeof(Message20),
                typeof(Message21), typeof(Message22)
            };

            var tasksCompleted = messageTypes.ToDictionary(k => k, v => new TaskCompletionSource <bool>());

            IAmazonSqsHost host = null;

            var busControl = Bus.Factory.CreateUsingAmazonSqs(cfg =>
            {
                host = cfg.Host("ap-southeast-2", h =>
                {
                    h.AccessKey(AwsAccessKey);
                    h.SecretKey(AwsSecretKey);
                });

                Func <object, Task> receiveTask = t =>
                {
                    tasksCompleted[t.GetType()].SetResult(true);
                    return(Util.TaskUtil.Completed);
                };

                cfg.ReceiveEndpoint(host, "long_multi_subs_queue", e =>
                {
                    e.Handler <Message0>(async c => await receiveTask(c.Message));
                    e.Handler <Message1>(async c => await receiveTask(c.Message));
                    e.Handler <Message2>(async c => await receiveTask(c.Message));
                    e.Handler <Message3>(async c => await receiveTask(c.Message));
                    e.Handler <Message4>(async c => await receiveTask(c.Message));
                    e.Handler <Message5>(async c => await receiveTask(c.Message));
                    e.Handler <Message6>(async c => await receiveTask(c.Message));
                    e.Handler <Message7>(async c => await receiveTask(c.Message));
                    e.Handler <Message8>(async c => await receiveTask(c.Message));
                    e.Handler <Message9>(async c => await receiveTask(c.Message));
                    e.Handler <Message10>(async c => await receiveTask(c.Message));
                    e.Handler <Message11>(async c => await receiveTask(c.Message));
                    e.Handler <Message12>(async c => await receiveTask(c.Message));
                    e.Handler <Message13>(async c => await receiveTask(c.Message));
                    e.Handler <Message14>(async c => await receiveTask(c.Message));
                    e.Handler <Message15>(async c => await receiveTask(c.Message));
                    e.Handler <Message16>(async c => await receiveTask(c.Message));
                    e.Handler <Message17>(async c => await receiveTask(c.Message));
                    e.Handler <Message18>(async c => await receiveTask(c.Message));
                    e.Handler <Message19>(async c => await receiveTask(c.Message));
                    e.Handler <Message20>(async c => await receiveTask(c.Message));
                    e.Handler <Message21>(async c => await receiveTask(c.Message));
                    e.Handler <Message22>(async c => await receiveTask(c.Message));
                });
            });

            await busControl.StartAsync();

            var publishTasks = messageTypes.Select(m => busControl.Publish(Activator.CreateInstance(m)));
            await Task.WhenAll(publishTasks);

            var awaitTasks = tasksCompleted.Values.Select(async t => await t.Task.OrTimeout(TimeSpan.FromSeconds(20)));
            await Task.WhenAll(awaitTasks);

            await busControl.StopAsync();
        }
Exemple #12
0
        protected override void ConfigureAmazonSqsBusHost(IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host)
        {
            configurator.ReceiveEndpoint(host, "input_queue_error", x =>
            {
                x.SubscribeMessageTopics = false;

                _errorHandler = Handled <PingMessage>(x);
            });
        }
Exemple #13
0
        /// <summary>
        /// Declare a ReceiveEndpoint using a unique generated queue name. This queue defaults to auto-delete
        /// and non-durable. By default all services bus instances include a default receiveEndpoint that is
        /// of this type (created automatically upon the first receiver binding).
        /// </summary>
        /// <param name="configurator"></param>
        /// <param name="host"></param>
        /// <param name="configure"></param>
        public static void ReceiveEndpoint(this IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host,
                                           Action <IAmazonSqsReceiveEndpointConfigurator> configure)
        {
            var queueName = host.Topology.CreateTemporaryQueueName("receiveEndpoint-");

            configurator.ReceiveEndpoint(host, queueName, x =>
            {
                x.AutoDelete = true;
                x.Durable    = false;

                configure(x);
            });
        }
Exemple #14
0
 protected virtual IAgent <ModelContext> GetModelAgent(IAmazonSqsHost host)
 {
     return(new AmazonSqsModelCache(host, host.ConnectionCache));
 }
        protected override void ConfigureAmazonSqsBusHost(IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host)
        {
            configurator.ReceiveEndpoint(host, "input_queue_error", x =>
            {
                x.ConfigureConsumeTopology = false;
                x.PurgeOnStartup           = true;

                _errorHandler = Handled <PingMessage>(x);
            });
        }
 public AmazonSqsModelCache(IAmazonSqsHost host, IConnectionCache connectionCache)
     : base(new ModelContextFactory(connectionCache, host))
 {
 }
        public void SetComplete(IAmazonSqsHost host)
        {
            _host = host;

            base.SetComplete(host);
        }
 public static void ReceiveEndpoint(this IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host, IEndpointDefinition definition,
                                    Action <IAmazonSqsReceiveEndpointConfigurator> configure = null)
 {
     configurator.ReceiveEndpoint(definition, DefaultEndpointNameFormatter.Instance, configure);
 }
Exemple #19
0
        protected override void ConfigureAmazonSqsBusHost(IAmazonSqsBusFactoryConfigurator configurator, IAmazonSqsHost host)
        {
            base.ConfigureAmazonSqsBusHost(configurator, host);

            configurator.UseAmazonSqsMessageScheduler();
        }