public void LogMoved( ISilverbackLogger logger, IRawInboundEnvelope envelope, IProducerEndpoint targetEndpoint) { if (!logger.IsEnabled(IntegrationLogEvents.MessageMoved)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( envelope.Endpoint, envelope.Headers, envelope.BrokerMessageIdentifier); _messageMoved.Invoke( logger.InnerLogger, targetEndpoint.DisplayName, envelope.ActualEndpointDisplayName, envelope.Headers.GetValue(DefaultMessageHeaders.MessageType), envelope.Headers.GetValue(DefaultMessageHeaders.MessageId), value1, value2, null); }
public ProcessedOutboundEnvelope( Stream?messageStream, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint) : base(messageStream, headers, endpoint) { }
public MoveMessageErrorPolicyImplementation( IProducerEndpoint endpoint, Action <IOutboundEnvelope, Exception>?transformationAction, int?maxFailedAttempts, ICollection <Type> excludedExceptions, ICollection <Type> includedExceptions, Func <IRawInboundEnvelope, Exception, bool>?applyRule, Func <IRawInboundEnvelope, object>?messageToPublishFactory, IServiceProvider serviceProvider, IInboundLogger <MoveMessageErrorPolicy> logger) : base( maxFailedAttempts, excludedExceptions, includedExceptions, applyRule, messageToPublishFactory, serviceProvider, logger) { _endpoint = Check.NotNull(endpoint, nameof(endpoint)); _transformationAction = transformationAction; _logger = logger; _producer = serviceProvider.GetRequiredService <IBrokerCollection>().GetProducer(endpoint); }
public void LogProduced( ISilverbackLogger logger, IProducerEndpoint endpoint, string actualEndpoint, IReadOnlyCollection <MessageHeader>?headers, IBrokerMessageIdentifier?brokerMessageIdentifier) { if (!logger.IsEnabled(IntegrationLogEvents.MessageProduced)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( endpoint, headers, brokerMessageIdentifier); _messageProduced.Invoke( logger.InnerLogger, actualEndpoint, headers?.GetValue(DefaultMessageHeaders.MessageType), headers?.GetValue(DefaultMessageHeaders.MessageId), value1, value2, null); }
public void LogProduceError( ISilverbackLogger logger, IProducerEndpoint endpoint, string actualEndpoint, IReadOnlyCollection <MessageHeader>?headers, Exception exception) { if (!logger.IsEnabled(IntegrationLogEvents.MessageProduced)) { return; } (string?value1, string?value2) = _logEnricher.GetAdditionalValues( endpoint, headers, null); _errorProducingMessage.Invoke( logger.InnerLogger, actualEndpoint, headers?.GetValue(DefaultMessageHeaders.MessageType), headers?.GetValue(DefaultMessageHeaders.MessageId), value1, value2, exception); }
public void LogProduced( IProducerEndpoint endpoint, string actualEndpointName, IReadOnlyCollection <MessageHeader>?headers, IBrokerMessageIdentifier?brokerMessageIdentifier) { }
/// <inheritdoc cref="IBroker.GetProducer" /> public virtual IProducer GetProducer(IProducerEndpoint endpoint) { Check.NotNull(endpoint, nameof(endpoint)); if (_producers == null) { throw new ObjectDisposedException(GetType().FullName); } return(_producers.GetOrAdd( endpoint, _ => { _logger.LogInformation( IntegrationEventIds.CreatingNewProducer, "Creating new producer for endpoint {endpointName}. (Total producers: {ProducerCount})", endpoint.Name, _producers.Count + 1); return InstantiateProducer( (TProducerEndpoint)endpoint, _serviceProvider.GetRequiredService <IBrokerBehaviorsProvider <IProducerBehavior> >(), _serviceProvider); })); }
public void LogProduceError( IProducerEndpoint endpoint, string actualEndpointName, IReadOnlyCollection <MessageHeader>?headers, Exception exception) { }
public void LogProduced( IProducerEndpoint endpoint, string actualEndpointName, IReadOnlyCollection <MessageHeader>?headers, IBrokerMessageIdentifier?brokerMessageIdentifier) => _loggerFactory.GetOutboundLogger(endpoint) .LogProduced(this, endpoint, actualEndpointName, headers, brokerMessageIdentifier);
public ProcessedOutboundEnvelope( byte[]?messageContent, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint) : base(messageContent, headers, endpoint) { }
public RawOutboundEnvelope( IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint, IBrokerMessageIdentifier?brokerMessageIdentifier = null) : this(null, headers, endpoint, brokerMessageIdentifier) { }
public OutboundEnvelope( TMessage message, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, bool autoUnwrap = false) : base(message, headers, endpoint, autoUnwrap) { }
public OutboundEnvelope( TMessage message, IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint, bool autoUnwrap = false) : base(message, headers, endpoint, autoUnwrap) { }
public RawOutboundEnvelope( IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, IOffset?offset = null, IDictionary <string, string>?additionalLogData = null) : this(null, headers, endpoint, offset, additionalLogData) { }
public RawOutboundEnvelope( IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, IBrokerMessageIdentifier?brokerMessageIdentifier = null, IDictionary <string, string>?additionalLogData = null) : this(null, headers, endpoint, brokerMessageIdentifier, additionalLogData) { }
/// <summary> /// Initializes a new instance of the <see cref="MoveMessageErrorPolicy" /> class. /// </summary> /// <param name="endpoint"> /// The endpoint to move the message to. /// </param> public MoveMessageErrorPolicy(IProducerEndpoint endpoint) { Check.NotNull(endpoint, nameof(endpoint)); endpoint.Validate(); Endpoint = endpoint; }
public RawOutboundEnvelope( Stream?rawMessage, IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint, IBrokerMessageIdentifier?brokerMessageIdentifier = null) : base(rawMessage, headers, endpoint) { BrokerMessageIdentifier = brokerMessageIdentifier; ActualEndpointName = endpoint.Name; }
public RawOutboundEnvelope( Stream?rawMessage, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, IOffset?offset = null, IDictionary <string, string>?additionalLogData = null) : base(rawMessage, headers, endpoint, additionalLogData) { Offset = offset; }
public RawOutboundEnvelope( Stream?rawMessage, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, IBrokerMessageIdentifier?brokerMessageIdentifier = null, IDictionary <string, string>?additionalLogData = null) : base(rawMessage, headers, endpoint, additionalLogData) { BrokerMessageIdentifier = brokerMessageIdentifier; }
/// <inheritdoc cref="IErrorPolicyChainBuilder.ThenMove(IProducerEndpoint, Action{MoveMessageErrorPolicy}?)" /> public IErrorPolicyChainBuilder ThenMove( IProducerEndpoint endpoint, Action <MoveMessageErrorPolicy>?policyConfigurationAction = null) { var policy = new MoveMessageErrorPolicy(endpoint); policyConfigurationAction?.Invoke(policy); _errorPolicies.Add(policy); return(this); }
private static void PreloadProducer( IBrokerCollection brokers, IProducerEndpoint endpoint, ISilverbackLogger logger) { if (!endpoint.IsValid(logger)) { return; } brokers.GetProducer(endpoint); }
public void LogProduceError( IProducerEndpoint endpoint, string actualEndpointName, IReadOnlyCollection <MessageHeader>?headers, Exception exception) => _loggerFactory.GetOutboundLogger(endpoint) .LogProduceError( this, endpoint, actualEndpointName, headers, exception);
/// <inheritdoc cref="IBrokerCollection.GetProducer" /> public IProducer GetProducer(IProducerEndpoint endpoint) { Check.NotNull(endpoint, nameof(endpoint)); var endpointType = endpoint.GetType(); return(FindBroker( broker => broker.ProducerEndpointType, endpointType, _producerEndpointTypeMap) .GetProducer(endpoint)); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="endpoint"> /// The <see cref="IProducerEndpoint" /> representing the destination topic or queue. /// </param> /// <param name="preloadProducers"> /// Specifies whether the producers must be immediately instantiated and connected. When <c>false</c> the /// <see cref="IProducer" /> will be created only when the first message is about to be produced. /// </param> /// <typeparam name="TMessage"> /// The type of the messages to be published to this endpoint. /// </typeparam> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound <TMessage>( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IProducerEndpoint endpoint, bool preloadProducers = true) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoint, nameof(endpoint)); return(endpointsConfigurationBuilder.AddOutbound( typeof(TMessage), new[] { endpoint }, preloadProducers)); }
/// <summary> /// Gets the producer for the specified endpoint and produces the specified message. /// </summary> /// <param name="content"> /// The serialized message content (body). /// </param> /// <param name="headers"> /// The collection of message headers. /// </param> /// <param name="endpoint"> /// The endpoint to produce to. /// </param> /// <param name="actualEndpointName"> /// The actual endpoint name that was resolved for the message. /// </param> /// <param name="onSuccess"> /// The callback to be invoked when the message is successfully produced. /// </param> /// <param name="onError"> /// The callback to be invoked when the produce fails. /// </param> /// <returns> /// A <see cref="Task" /> representing the asynchronous operation. /// </returns> protected virtual Task ProduceMessageAsync( byte[]?content, IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint, string actualEndpointName, Action <IBrokerMessageIdentifier?> onSuccess, Action <Exception> onError) => _brokerCollection.GetProducer(endpoint).RawProduceAsync( actualEndpointName, content, headers, onSuccess, onError);
/// <summary> /// Initializes a new instance of the <see cref="Producer" /> class. /// </summary> /// <param name="broker"> /// The <see cref="IBroker" /> that instantiated this producer. /// </param> /// <param name="endpoint"> /// The endpoint to produce to. /// </param> /// <param name="behaviorsProvider"> /// The <see cref="IBrokerBehaviorsProvider{TBehavior}" />. /// </param> /// <param name="serviceProvider"> /// The <see cref="IServiceProvider" /> to be used to resolve the needed services. /// </param> /// <param name="logger"> /// The <see cref="IOutboundLogger{TCategoryName}" />. /// </param> protected Producer( IBroker broker, IProducerEndpoint endpoint, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IServiceProvider serviceProvider, IOutboundLogger<Producer> logger) { Broker = Check.NotNull(broker, nameof(broker)); Endpoint = Check.NotNull(endpoint, nameof(endpoint)); _behaviors = Check.NotNull(behaviorsProvider, nameof(behaviorsProvider)).GetBehaviorsList(); _serviceProvider = Check.NotNull(serviceProvider, nameof(serviceProvider)); _logger = Check.NotNull(logger, nameof(logger)); Endpoint.Validate(); }
private async Task <EndpointCheckResult> PingEndpointAsync(IProducerEndpoint endpoint) { try { await _brokerCollection.GetProducer(endpoint).ProduceAsync(PingMessage.New()).ConfigureAwait(false); return(new EndpointCheckResult(endpoint.Name, true)); } catch (Exception ex) { return(new EndpointCheckResult( endpoint.Name, false, $"[{ex.GetType().FullName}] {ex.Message}")); } }
public IOutboundEnvelope CreateOutboundEnvelope( object?message, IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint) => message == null ? new OutboundEnvelope( message, headers, endpoint, _routingConfiguration.PublishOutboundMessagesToInternalBus) : (IOutboundEnvelope)Activator.CreateInstance( typeof(OutboundEnvelope <>).MakeGenericType(message.GetType()), message, headers, endpoint, _routingConfiguration.PublishOutboundMessagesToInternalBus);
public OutboundEnvelope( object?message, IReadOnlyCollection <MessageHeader>?headers, IProducerEndpoint endpoint, bool autoUnwrap = false, IBrokerMessageIdentifier?brokerMessageIdentifier = null) : base(headers, endpoint, brokerMessageIdentifier) { _message = message; if (Message is byte[] rawMessage) { RawMessage = new MemoryStream(rawMessage); } if (Message is Stream stream) { RawMessage = stream; } AutoUnwrap = autoUnwrap; }
public OutboundEnvelope( object?message, IEnumerable <MessageHeader>?headers, IProducerEndpoint endpoint, bool autoUnwrap = false, IOffset?offset = null) : base(headers, endpoint, offset) { _message = message; if (Message is byte[] rawMessage) { RawMessage = new MemoryStream(rawMessage); } if (Message is Stream stream) { RawMessage = stream; } AutoUnwrap = autoUnwrap; }