Ejemplo n.º 1
0
        public DurableWorkerQueue(Endpoint endpoint, IHandlerPipeline pipeline,
                                  AdvancedSettings settings, IEnvelopePersistence persistence, ITransportLogger logger)
        {
            _settings    = settings;
            _persistence = persistence;
            _logger      = logger;

            endpoint.ExecutionOptions.CancellationToken = settings.Cancellation;

            _receiver = new ActionBlock <Envelope>(async envelope =>
            {
                try
                {
                    envelope.ContentType = envelope.ContentType ?? "application/json";

                    await pipeline.Invoke(envelope, this);
                }
                catch (Exception e)
                {
                    // This *should* never happen, but of course it will
                    logger.LogException(e);
                }
            }, endpoint.ExecutionOptions);

            _policy = Policy
                      .Handle <Exception>()
                      .WaitAndRetryForeverAsync(i => (i * 100).Milliseconds()
                                                , (e, timeSpan) => {
                _logger.LogException(e);
            });
        }
Ejemplo n.º 2
0
        public LightweightWorkerQueue(Endpoint endpoint, ITransportLogger logger,
                                      IHandlerPipeline pipeline, AdvancedSettings settings)
        {
            _logger   = logger;
            _settings = settings;
            Pipeline  = pipeline;

            _scheduler = new InMemoryScheduledJobProcessor(this);

            endpoint.ExecutionOptions.CancellationToken = settings.Cancellation;

            _receiver = new ActionBlock <Envelope>(async envelope =>
            {
                try
                {
                    if (envelope.ContentType.IsEmpty())
                    {
                        envelope.ContentType = "application/json";
                    }

                    await Pipeline.Invoke(envelope);
                }
                catch (Exception e)
                {
                    // This *should* never happen, but of course it will
                    logger.LogException(e);
                }
            }, endpoint.ExecutionOptions);
        }
Ejemplo n.º 3
0
        public void StartTransports(IHandlerPipeline pipeline, BusSettings settings, ITransport[] transports)
        {
            Name            = settings.ServiceName;
            ValidTransports = transports.Select(x => x.Protocol).ToArray();


            foreach (var transport in transports)
            {
                var channels = transport.Start(pipeline, settings, this);
                foreach (var channel in channels)
                {
                    _channels[channel.Uri] = channel;
                }
            }

            if (settings.DefaultChannelAddress != null)
            {
                DefaultChannel = this[settings.DefaultChannelAddress];
            }

            assertNoUnknownTransportsInSubscribers(settings);


            assertNoUnknownTransportsInListeners(settings);
        }
Ejemplo n.º 4
0
        // TODO -- just pull in MessagingRoot?
        public MessageContext(IMessageRouter router, IReplyWatcher watcher, IHandlerPipeline pipeline, MessagingSerializationGraph serialization, MessagingSettings settings, IChannelGraph channels, IDurableMessagingFactory factory, IMessageLogger logger, Envelope originalEnvelope)
        {
            _router        = router;
            _watcher       = watcher;
            _pipeline      = pipeline;
            _serialization = serialization;
            _settings      = settings;
            _channels      = channels;
            Factory        = factory;
            _logger        = logger;

            Envelope = originalEnvelope;
            _sagaId  = originalEnvelope.SagaId;


            var persistor = new InMemoryEnvelopeTransaction();

            EnlistedInTransaction = true;
            Transaction           = persistor;

            if (Envelope.AckRequested)
            {
                var ack = buildAcknowledgement();

                persistor.Queued.Fill(ack);
                _outstanding.Add(ack);
            }
        }
        public MartenBackedListenerContext()
        {
            theStore = DocumentStore.For(_ =>
            {
                _.Connection(Servers.PostgresConnectionString);
                _.PLV8Enabled = false;
            });


            theSettings = new AdvancedSettings(null);


            EnvelopeStorageAdmin.RebuildSchemaObjects();

            var persistence =
                new PostgresqlEnvelopePersistence(
                    new PostgresqlSettings {
                ConnectionString = Servers.PostgresConnectionString
            }, theSettings);

            thePipeline    = Substitute.For <IHandlerPipeline>();
            theWorkerQueue = new DurableWorkerQueue(new LocalQueueSettings("temp"), thePipeline, theSettings,
                                                    persistence, TransportLogger.Empty());


            var agent = Substitute.For <IListener>();

            theWorkerQueue.StartListening(agent);
        }
Ejemplo n.º 6
0
 public ServiceBus(IEnvelopeSender sender, IReplyWatcher watcher, IHandlerPipeline pipeline, SerializationGraph serialization)
 {
     _sender        = sender;
     _watcher       = watcher;
     _pipeline      = pipeline;
     _serialization = serialization;
 }
Ejemplo n.º 7
0
 public Receiver(IHandlerPipeline pipeline, ChannelGraph graph, ChannelNode node)
 {
     _pipeline = pipeline;
     _graph = graph;
     _node = node;
     _address = node.Channel.Address;
 }
Ejemplo n.º 8
0
 public Receiver(IHandlerPipeline pipeline, ChannelGraph graph, ChannelNode node)
 {
     _pipeline = pipeline;
     _graph    = graph;
     _node     = node;
     _address  = node.Uri;
 }
Ejemplo n.º 9
0
 public QueueCollection(IBusLogger logger, IQueueProvider provider, IHandlerPipeline pipeline, CancellationToken cancellationToken)
 {
     _logger            = logger;
     _pipeline          = pipeline;
     _cancellationToken = cancellationToken;
     _provider          = provider;
 }
 public TransportActivator(ChannelGraph graph, IServiceLocator services, IHandlerPipeline pipeline, IEnumerable<ITransport> transports)
 {
     _graph = graph;
     _services = services;
     _pipeline = pipeline;
     _transports = transports;
 }
 public LightweightLocalSendingAgent(Endpoint endpoint, ITransportLogger logger,
                                     IHandlerPipeline pipeline, AdvancedSettings settings, IMessageLogger messageLogger) : base(endpoint, logger, pipeline, settings)
 {
     _messageLogger = messageLogger;
     Destination    = Address = endpoint.Uri;
     Endpoint       = endpoint;
 }
Ejemplo n.º 12
0
        private async Task ConsumeAsync(IHandlerPipeline pipeline)
        {
            await foreach (Message message in _consumer.Messages(_cancellation))
            {
                Envelope envelope;

                try
                {
                    envelope = _protocol.ReadEnvelope(new DotPulsarMessage(message.Data, message.Properties));
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error trying to map an incoming Pulsar {_endpoint.Topic} Topic message to an Envelope. See the Dead Letter Queue");
                    continue;
                }

                try
                {
                    IChannelCallback channelCallback = new DotPulsarChannelCallback(message.MessageId, _consumer);
                    await pipeline.Invoke(envelope, channelCallback);
                }
                catch (Exception e)
                {
                    // DotPulsar currently doesn't support Nack so will likely just keep retrying message for now.
                    _logger.LogException(e, envelope.Id, "Error trying to receive a message from " + Address);
                }
            }
        }
Ejemplo n.º 13
0
        public void StartHandlingInline(IHandlerPipeline pipeline)
        {
            _consumer.Subscribe(new[] { _endpoint.TopicName });

            _consumerTask = ConsumeAsync(pipeline);

            _logger.ListeningStatusChange(ListeningStatus.Accepting);
        }
 public TransportActivator(ChannelGraph graph, IServiceLocator services, IHandlerPipeline pipeline, IEnumerable <ITransport> transports, IEnumerable <IFubuTransportActivator> fubuTransportActivators)
 {
     _graph      = graph;
     _services   = services;
     _pipeline   = pipeline;
     _transports = transports;
     _fubuTransportActivators = fubuTransportActivators;
 }
Ejemplo n.º 15
0
 public EnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline)
 {
     this.logger = logger;
     _systemTime = systemTime;
     _invoker    = invoker;
     Outgoing    = outgoing;
     _pipeline   = pipeline;
 }
Ejemplo n.º 16
0
        public TestEnvelopeContext(IHandlerPipeline handlerPipeline)
            : base(new RecordingLogger(), new SettableClock(), MockRepository.GenerateMock<IChainInvoker>(),
                new RecordingEnvelopeSender(), handlerPipeline)
        {
            SystemTime.As<SettableClock>().LocalNow(DateTime.Today.AddHours(5));

            HandlerPipeline = handlerPipeline;
        }
        public ProductionDiagnosticEnvelopeContext(ILogger logger, ISystemTime systemTime, IChainInvoker invoker, IOutgoingSender outgoing, IHandlerPipeline pipeline, Envelope envelope, IExecutionLogger executionLogger)
            : base(logger, systemTime, invoker, outgoing, pipeline)
        {
            _envelope = envelope;
            _executionLogger = executionLogger;
            _log = new ChainExecutionLog();

            _envelope.Log = _log;
        }
Ejemplo n.º 18
0
        public TestEnvelopeContext(IHandlerPipeline handlerPipeline)
            : base(
                new RecordingLogger(), new SettableClock(), MockRepository.GenerateMock <IChainInvoker>(),
                new RecordingEnvelopeSender(), handlerPipeline)
        {
            SystemTime.As <SettableClock>().LocalNow(DateTime.Today.AddHours(5));

            HandlerPipeline = handlerPipeline;
        }
Ejemplo n.º 19
0
 public TransportActivator(ChannelGraph graph, IServiceLocator services, IHandlerPipeline pipeline, ILogger logger, IEnumerable<ITransport> transports, IEnumerable<IFubuTransportActivator> fubuTransportActivators)
 {
     _graph = graph;
     _services = services;
     _pipeline = pipeline;
     _logger = logger;
     _transports = transports;
     _fubuTransportActivators = fubuTransportActivators;
 }
Ejemplo n.º 20
0
        public StubTransport(IHandlerPipeline pipeline)

        {
            _pipeline     = pipeline;
            LocalReplyUri = new Uri($"stub://replies");

            Channels =
                new LightweightCache <Uri, StubChannel>(uri => new StubChannel(uri, pipeline, this));
        }
Ejemplo n.º 21
0
 public ServiceBus(IEnvelopeSender sender, IReplyWatcher watcher, IHandlerPipeline pipeline, BusMessageSerializationGraph serialization, BusSettings settings, IChannelGraph channels, IPersistence persistence)
 {
     _sender        = sender;
     _watcher       = watcher;
     _pipeline      = pipeline;
     _serialization = serialization;
     _settings      = settings;
     _channels      = channels;
     _persistence   = persistence;
 }
Ejemplo n.º 22
0
 public ServiceBusActivator(BusSettings settings, IHandlerPipeline pipeline, IDelayedJobProcessor delayedJobs, SerializationGraph serialization, IEnumerable <ITransport> transports, UriAliasLookup lookups, INodeDiscovery nodes)
 {
     _settings      = settings;
     _pipeline      = pipeline;
     _delayedJobs   = delayedJobs;
     _serialization = serialization;
     _transports    = transports.ToArray();
     _lookups       = lookups;
     _nodes         = nodes;
 }
Ejemplo n.º 23
0
        public void StartReceiving(IHandlerPipeline pipeline, ILogger logger, ChannelGraph graph)
        {
            if (Channel == null)
            {
                throw new InvalidOperationException("Cannot receive on node {0} without a matching channel".ToFormat(SettingAddress));
            }
            var receiver = new Receiver(pipeline, graph, this);

            StartReceiving(receiver, logger);
        }
Ejemplo n.º 24
0
 public ServiceBus(IMessageRouter router, IReplyWatcher watcher, IHandlerPipeline pipeline, BusMessageSerializationGraph serialization, BusSettings settings, IChannelGraph channels, IPersistence persistence, CompositeMessageLogger logger)
 {
     _router        = router;
     _watcher       = watcher;
     _pipeline      = pipeline;
     _serialization = serialization;
     _settings      = settings;
     _channels      = channels;
     Persistence    = persistence;
     _logger        = logger;
 }
Ejemplo n.º 25
0
 // TODO -- just pull in MessagingRoot?
 public MessageContext(IMessageRouter router, IReplyWatcher watcher, IHandlerPipeline pipeline, MessagingSerializationGraph serialization, MessagingSettings settings, IChannelGraph channels, IDurableMessagingFactory factory, IMessageLogger logger)
 {
     _router        = router;
     _watcher       = watcher;
     _pipeline      = pipeline;
     _serialization = serialization;
     _settings      = settings;
     _channels      = channels;
     Factory        = factory;
     _logger        = logger;
 }
Ejemplo n.º 26
0
 public ServiceBusActivator(BusSettings settings, IHandlerPipeline pipeline, IDelayedJobProcessor delayedJobs, BusMessageSerializationGraph serialization, IEnumerable <ITransport> transports, UriAliasLookup lookups, IWorkerQueue workerQueue, CompositeLogger logger, IPersistence persistence)
 {
     _settings      = settings;
     _pipeline      = pipeline;
     _delayedJobs   = delayedJobs;
     _serialization = serialization;
     _transports    = transports.ToArray();
     _lookups       = lookups;
     _workerQueue   = workerQueue;
     _logger        = logger;
     _persistence   = persistence;
 }
Ejemplo n.º 27
0
        public IChannel[] Start(IHandlerPipeline pipeline, BusSettings settings, OutgoingChannels channels)
        {
            _pipeline = pipeline;

            foreach (var messageType in _handlers.Chains.Select(x => x.MessageType).Where(x => x.CanBeCastTo <ClientMessage>()))
            {
                JsonSerialization.RegisterType(messageType.ToMessageAlias(), messageType);
            }

            _retries = channels.DefaultRetryChannel;

            return(new IChannel[] { new OutgoingWebSocketChannel(this) });
        }
Ejemplo n.º 28
0
        public WorkerQueue(CompositeMessageLogger logger, IHandlerPipeline pipeline, BusSettings settings, CancellationToken cancellationToken)
        {
            _logger            = logger;
            _pipeline          = pipeline;
            _settings          = settings;
            _cancellationToken = cancellationToken;

            foreach (var worker in _settings.Workers.AllWorkers)
            {
                AddQueue(worker.Name, worker.Parallelization);
            }

            ScheduledJobs = InMemoryScheduledJobProcessor.ForQueue(this);
        }
Ejemplo n.º 29
0
        public DurableLocalSendingAgent(Endpoint endpoint, IHandlerPipeline pipeline,
                                        AdvancedSettings settings, IEnvelopePersistence persistence, ITransportLogger logger,
                                        MessagingSerializationGraph serializers, IMessageLogger messageLogger) : base(endpoint, pipeline, settings, persistence, logger)
        {
            _settings      = settings;
            _persistence   = persistence;
            _logger        = logger;
            _serializers   = serializers;
            _messageLogger = messageLogger;
            Destination    = endpoint.Uri;

            Endpoint = endpoint;
            ReplyUri = TransportConstants.RepliesUri;
        }
Ejemplo n.º 30
0
        public WorkerQueue(IMessageLogger logger, IHandlerPipeline pipeline, MessagingSettings settings)
        {
            _logger            = logger;
            Pipeline           = pipeline;
            _settings          = settings;
            _cancellationToken = _settings.Cancellation;

            foreach (var worker in Pipeline.Workers.AllWorkers)
            {
                AddQueue(worker.Name, worker.Parallelization);
            }

            ScheduledJobs = new InMemoryScheduledJobProcessor(this);
        }
Ejemplo n.º 31
0
        private async Task ConsumeAsync(IHandlerPipeline pipeline)
        {
            while (!_cancellation.IsCancellationRequested)
            {
                ConsumeResult <byte[], byte[]> message;
                try
                {
                    message = await Task.Run(() => _consumer.Consume(), _cancellation);
                }
                catch (Confluent.Kafka.ConsumeException cex)
                {
                    if (cex.Error.Code == ErrorCode.PolicyViolation)
                    {
                        throw;
                    }

                    continue;
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error consuming message from Kafka topic {_endpoint.TopicName}");
                    continue;
                }

                Envelope envelope;

                try
                {
                    envelope = _protocol.ReadEnvelope(message.Message);
                }
                catch (Exception ex)
                {
                    _logger.LogException(ex, message: $"Error trying to map an incoming Kafka {_endpoint.TopicName} Topic message to an Envelope. See the Dead Letter Queue");
                    continue;
                }

                try
                {
                    await pipeline.Invoke(envelope, new KafkaChannelCallback(message, _consumer));
                }
                catch (Exception e)
                {
                    // TODO -- Got to either discard this or defer it back to the queue
                    _logger.LogException(e, envelope.Id, "Error trying to receive a message from " + Address);
                }
            }
        }
Ejemplo n.º 32
0
        public QueueReceiver(IHandlerPipeline pipeline, string queueName, int maximumParallelization, IQueueProvider provider, CancellationToken cancellationToken)
        {
            _pipeline          = pipeline;
            _provider          = provider;
            _cancellationToken = cancellationToken;
            QueueName          = queueName;


            var options = new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = maximumParallelization,
                CancellationToken      = cancellationToken
            };


            _block = new ActionBlock <Envelope>(receive, options);
        }
Ejemplo n.º 33
0
        public void Start(IHandlerPipeline pipeline, ChannelGraph channels)
        {
            foreach (var node in channels.IncomingChannelsFor(Protocol))
            {
                var receiver = new Receiver(pipeline, channels, node);
                ReceiveAt(node, receiver);
            }

            var replyNode     = new ChannelNode(ReplyChannel.Address);
            var replyReceiver = new Receiver(pipeline, channels, replyNode);

            ReceiveAt(replyNode, replyReceiver);

            channels.Where(x => x.Uri.Scheme == Protocol).Each(x => {
                x.ReplyUri    = ReplyChannel.Address;
                x.Destination = x.Uri;
            });
        }
Ejemplo n.º 34
0
        public IChannel[] Start(IHandlerPipeline pipeline, BusSettings settings, OutgoingChannels channels)
        {
            _pipeline = pipeline;

            foreach (var address in settings.KnownSubscribers.Where(x => x.Uri.Scheme == Protocol))
            {
                Channels[address.Uri] = new StubChannel(address.Uri, _replyUri, pipeline, address);
            }

            foreach (var node in settings.Listeners.Where(x => x.Uri.Scheme == Protocol))
            {
                Channels.FillDefault(node.Uri);
            }



            return(Channels.GetAll().OfType <IChannel>().ToArray());
        }
        public SqlServerBackedListenerContext()
        {
            new SqlServerEnvelopeStorageAdmin(new SqlServerSettings{ConnectionString = Servers.SqlServerConnectionString}).RecreateAll();


            theSettings = new AdvancedSettings(null);

            mssqlSettings = new SqlServerSettings
            {
                ConnectionString = Servers.SqlServerConnectionString
            };

            ThePersistence = new SqlServerEnvelopePersistence(mssqlSettings, theSettings);


            thePipeline = Substitute.For<IHandlerPipeline>();
            theWorkerQueue = new DurableWorkerQueue(new LocalQueueSettings("temp"), thePipeline, theSettings, ThePersistence, TransportLogger.Empty());

        }
Ejemplo n.º 36
0
 public void StartReceiving(IHandlerPipeline pipeline, ILogger logger, ChannelGraph graph)
 {
     if (Channel == null) throw new InvalidOperationException("Cannot receive on node {0} without a matching channel".ToFormat(SettingAddress));
     var receiver = new Receiver(pipeline, graph, this);
     StartReceiving(receiver, logger);
 }