Exemple #1
0
            public async Task Should_be_asynchronous()
            {
                var shutdown = new CancellationTokenSource();

                var inputAddress = new Uri("loopback://localhost/input_queue");

                var transport = new InMemoryTransport(inputAddress, Environment.ProcessorCount);

                TaskCompletionSource <int> received = GetTask <int>();

                IPipe <ReceiveContext> receivePipe = Pipe.New <ReceiveContext>(x =>
                {
                    x.UseFilter(new DelegateFilter <ReceiveContext>(context =>
                    {
                        Console.WriteLine("Message: {0}", context.TransportHeaders.Get("MessageId", "N/A"));

                        received.TrySetResult(1);
                    }));
                });

                ReceiveTransportHandle receiveHandle = ((IReceiveTransport)transport).Start(receivePipe);

                var sendEndpoint = new SendEndpoint(transport, new JsonMessageSerializer(), inputAddress,
                                                    inputAddress);

                await sendEndpoint.Send(new A(), TestCancellationToken);

                await received.Task;

                shutdown.Cancel();

                await receiveHandle.Stop();
            }
            public async Task Should_be_asynchronous()
            {
                var shutdown = new CancellationTokenSource();

                var inputAddress = new Uri("loopback://localhost/input_queue");

                var transport = new InMemoryTransport(inputAddress, Environment.ProcessorCount);

                TaskCompletionSource<int> received = GetTask<int>();

                IPipe<ReceiveContext> receivePipe = Pipe.New<ReceiveContext>(x =>
                {
                    x.UseFilter(new DelegateFilter<ReceiveContext>(context =>
                    {
                        Console.WriteLine("Message: {0}", context.TransportHeaders.Get("MessageId", "N/A"));

                        received.TrySetResult(1);
                    }));
                });

                ReceiveTransportHandle receiveHandle = ((IReceiveTransport)transport).Start(receivePipe);

                var sendEndpoint = new SendEndpoint(transport, new JsonMessageSerializer(), inputAddress,
                    inputAddress, new SendPipe(new MessageTypeSendFilter(), Pipe.Empty<SendContext>()));

                await sendEndpoint.Send(new A(), TestCancellationToken);

                await received.Task;

                shutdown.Cancel();

                await receiveHandle.Stop();
            }
Exemple #3
0
        async Task <CachedSendEndpoint <TypeKey> > CreateSendEndpoint <T>(TypeKey typeKey)
            where T : class
        {
            var builder = _host.CreatePublishTopologyBuilder();

            _publishTopology.GetMessageTopology <T>().Apply(builder);

            ISendTransport exchange = await _host.GetSendTransport(typeKey.Address).ConfigureAwait(false);

            var sendEndpoint = new SendEndpoint(exchange, _serializer, typeKey.Address, _sourceAddress, SendPipe.Empty);

            return(new CachedSendEndpoint <TypeKey>(typeKey, sendEndpoint));
        }
        public Task <ISendEndpoint> GetSendEndpoint(Uri address)
        {
            if (address.Scheme == "reply")
            {
                var responseTransport = new HttpResponseTransport(_owinContext);

                var endpoint = new SendEndpoint(responseTransport, _receiveSettings.MessageSerializer, address, _inputAddress, _sendPipe);

                endpoint.ConnectSendObserver(_observers);

                return(Task.FromResult <ISendEndpoint>(endpoint));
            }

            return(_receiveSettings.SendEndpointProvider.GetSendEndpoint(address));
        }
        public Task<ISendEndpoint> GetSendEndpoint(Uri address)
        {
            if (address.Scheme == "reply")
            {
                var responseTransport = new HttpResponseTransport(_owinContext);

                var endpoint = new SendEndpoint(responseTransport, _receiveSettings.MessageSerializer, address, _inputAddress, _sendPipe);

                endpoint.ConnectSendObserver(_observers);

                return Task.FromResult<ISendEndpoint>(endpoint);
            }

            return _receiveSettings.SendEndpointProvider.GetSendEndpoint(address);
        }
        public EmailSendWorker(ILogger <EmailSendWorker> logger, IConfiguration configuration, IModel channel, SendEndpoint sendEndpoint)
        {
            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
            _channel            = channel ?? throw new ArgumentNullException(nameof(channel));
            _sendEndpoint       = sendEndpoint ?? throw new ArgumentNullException(nameof(sendEndpoint));
            _mailSendingQueueId = configuration.GetSection(_queuesConfigurationSection)
                                  .GetValue <string>(_emailSendQueueParameter);
            _statusUpdateQueueId = configuration.GetSection(_queuesConfigurationSection)
                                   .GetValue <string>(_emailStatusUpdateParameter);
            _channel.QueueDeclare(_mailSendingQueueId, true, false, false, null);
            _consumer           = new AsyncEventingBasicConsumer(_channel);
            _consumer.Received += MessageRecieved;
            _sandboxMode        = configuration.GetSection(_mailjetConfigurationSection).GetValue(_sandboxModeParameter, true);
        }
        Task <CachedSendEndpoint <TypeKey> > CreateSendEndpoint <T>(TypeKey typeKey, IRabbitMqMessagePublishTopology <T> publishTopology)
            where T : class
        {
            var sendSettings = publishTopology.GetSendSettings();

            var builder = new PublishEndpointBrokerTopologyBuilder(_host.Topology.PublishTopology.BrokerTopologyOptions);

            publishTopology.Apply(builder);

            var topology = builder.BuildTopologyLayout();

            var modelCache = new RabbitMqModelCache(_host);

            var sendTransport = new RabbitMqSendTransport(modelCache, new ConfigureTopologyFilter <SendSettings>(sendSettings, topology),
                                                          sendSettings.ExchangeName);

            sendTransport.ConnectSendObserver(_sendObservable);

            var sendEndpoint = new SendEndpoint(sendTransport, _serializer, typeKey.Address, _sourceAddress, SendPipe.Empty);

            return(Task.FromResult(new CachedSendEndpoint <TypeKey>(typeKey, sendEndpoint)));
        }
Exemple #8
0
        Task <CachedSendEndpoint <Type> > CreateSendEndpoint(Type messageType)
        {
            if (!TypeMetadataCache.IsValidMessageType(messageType))
            {
                throw new MessageException(messageType, "Anonymous types are not valid message types");
            }

            var sendSettings = _host.Settings.GetSendSettings(messageType);

            ExchangeBindingSettings[] bindings = TypeMetadataCache.GetMessageTypes(messageType)
                                                 .SelectMany(type => type.GetExchangeBindings(_host.Settings.MessageNameFormatter))
                                                 .Where(binding => !sendSettings.ExchangeName.Equals(binding.Exchange.ExchangeName))
                                                 .ToArray();

            var destinationAddress = sendSettings.GetSendAddress(_host.Settings.HostAddress);

            var modelCache = new RabbitMqModelCache(_host);

            var sendTransport = new RabbitMqSendTransport(modelCache, sendSettings, bindings);

            var sendEndpoint = new SendEndpoint(sendTransport, _serializer, destinationAddress, _sourceAddress, SendPipe.Empty);

            return(Task.FromResult(new CachedSendEndpoint <Type>(messageType, sendEndpoint)));
        }