/// <summary> /// Adds and inbound endpoint. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="endpoint"> /// The endpoint (topic). /// </param> /// <param name="consumersCount"> /// The number of consumers to be instantiated. The default is 1. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddInbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IConsumerEndpoint endpoint, int consumersCount = 1) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoint, nameof(endpoint)); if (consumersCount <= 0) { throw new ArgumentException( "The consumers count must be greater or equal to 1.", nameof(consumersCount)); } var serviceProvider = endpointsConfigurationBuilder.ServiceProvider; var brokerCollection = serviceProvider.GetRequiredService <IBrokerCollection>(); for (int i = 0; i < consumersCount; i++) { brokerCollection.AddConsumer(endpoint); } return(endpointsConfigurationBuilder); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddMqttEndpoints( endpoints => endpoints // Configure the client options .Configure( config => config .WithClientId("samples.basic.consumer") .ConnectViaTcp("localhost") // Send last will message if disconnecting // ungracefully .SendLastWillMessage( lastWill => lastWill .Message(new TestamentMessage()) .ProduceTo("samples/testaments"))) // Consume the samples/basic topic .AddInbound( endpoint => endpoint .ConsumeFrom("samples/basic") .WithQualityOfServiceLevel( MqttQualityOfServiceLevel.AtLeastOnce) // Silently skip the messages in case of exception .OnError(policy => policy.Skip()))); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="endpoints"> /// The collection of <see cref="IProducerEndpoint" /> representing the destination topics or queues. /// </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> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IEnumerable <IProducerEndpoint> endpoints, bool preloadProducers = true) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(messageType, nameof(messageType)); Check.NotNull(endpoints, nameof(endpoints)); IEnumerable <IProducerEndpoint> endpointsToRegister; if (endpointsConfigurationBuilder.GetOutboundRoutingConfiguration() .IdempotentEndpointRegistration) { endpointsToRegister = endpointsConfigurationBuilder.FilterRegisteredEndpoints(endpoints, messageType); } else { endpointsToRegister = endpoints; } return(endpointsConfigurationBuilder.AddOutbound( messageType, new StaticOutboundRouter(endpointsToRegister), preloadProducers)); }
public void Configure(IEndpointsConfigurationBuilder builder) { // Consume the samples-binary-file-streaming topic builder.AddInbound( new KafkaConsumerEndpoint("samples-binary-file-streaming") { Configuration = new KafkaConsumerConfig { // The consumer needs at least the bootstrap server address and a group id to be able to connect BootstrapServers = "PLAINTEXT://localhost:9092", GroupId = GetType().Assembly.FullName ?? "sample-consumer", // AutoOffsetReset.Earliest means that the consumer must start consuming from the beginning of // the topic, if no offset was stored for this consumer group AutoOffsetReset = AutoOffsetReset.Earliest }, // Force the consumer to use the BinaryFileMessageSerializer: this is not strictly necessary when // the messages are produced by Silverback but it increases the interoperability, since it doesn't // have to rely on the 'x-message-type' header value to switch to the BinaryFileMessageSerializer. // // In this example the BinaryFileMessageSerializer is also set to return a CustomBinaryFileMessage // instead of the normal BinaryFileMessage. This is only needed because we want to read the custom // 'x-message-filename' header, otherwise 'Serializer = BinaryFileMessageSerializer.Default' would // work perfectly fine (returning a basic BinaryFileMessage, without the extra properties). Serializer = new BinaryFileMessageSerializer <CustomBinaryFileMessage>(), // Retry each chunks sequence 5 times in case of an exception ErrorPolicy = ErrorPolicy.Retry(5) }); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddKafkaEndpoints( endpoints => endpoints // Configure the properties needed by all consumers/producers .Configure( config => { // The bootstrap server address is needed to connect config.BootstrapServers = "PLAINTEXT://localhost:9092"; }) // Produce the binary files to the // samples-binary-file-streaming topic .AddOutbound <BinaryFileMessage>( endpoint => endpoint // Force producing to a specific partition (0 in this // case) to be able to scale to multiple producers // writing to the same topic. Assigning a different // partition to each one will ensure that the chunks // are always contiguous. // This isn't mandatory and necessary only when // horizontally scaling the producer. // (In the final solution the "0" constant value // should be replaced by a configuration setting.) .ProduceTo("samples-binary-file-streaming", 0) // Split the binary files into chunks of 512 kB .EnableChunking(524288))); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddMqttEndpoints( endpoints => endpoints // Configure the client options .Configure( config => config .WithClientId("samples.basic.consumer") .ConnectViaTcp("localhost") .UseProtocolVersion(MqttProtocolVersion.V310) // Send last will message if disconnecting // ungracefully .SendLastWillMessage( lastWill => lastWill .Message(new TestamentMessage()) .ProduceTo("samples/testaments"))) // Consume the samples/basic topic // Note: It is mandatory to specify the message type, since // MQTT 3 doesn't support message headers (aka user // properties) .AddInbound <SampleMessage>( endpoint => endpoint .ConsumeFrom("samples/basic") .WithQualityOfServiceLevel( MqttQualityOfServiceLevel.AtLeastOnce) // Silently skip the messages in case of exception .OnError(policy => policy.Skip()))); }
/// <summary> /// Adds an inbound endpoint and instantiates a consumer. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="endpoint"> /// The endpoint (topic). /// </param> /// <param name="consumersCount"> /// The number of consumers to be instantiated. The default is 1. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddInbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IConsumerEndpoint endpoint, int consumersCount = 1) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoint, nameof(endpoint)); if (consumersCount <= 0) { throw new ArgumentOutOfRangeException( nameof(consumersCount), consumersCount, "The consumers count must be greater or equal to 1."); } var serviceProvider = endpointsConfigurationBuilder.ServiceProvider; var brokerCollection = serviceProvider.GetRequiredService <IBrokerCollection>(); var logger = serviceProvider.GetRequiredService <ISilverbackLogger <IEndpointsConfigurationBuilder> >(); if (!endpoint.IsValid(logger)) { return(endpointsConfigurationBuilder); } for (int i = 0; i < consumersCount; i++) { brokerCollection.AddConsumer(endpoint); } return(endpointsConfigurationBuilder); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddKafkaEndpoints( endpoints => endpoints // Configure the properties needed by all consumers/producers .Configure( config => { // The bootstrap server address is needed to connect config.BootstrapServers = "PLAINTEXT://localhost:9092"; }) // Consume the samples-basic topic .AddInbound( endpoint => endpoint .ConsumeFrom("samples-basic") .Configure( config => { // The consumer needs at least the bootstrap server address // and a group id to be able to connect config.GroupId = "sample-consumer"; // AutoOffsetReset.Earliest means that the consumer must start // consuming from the beginning of the topic, if no offset was // stored for this consumer group config.AutoOffsetReset = AutoOffsetReset.Earliest; }))); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <typeparam name="TMessage"> /// The type of the messages to be published to this endpoint. /// </typeparam> /// <typeparam name="TRouter"> /// The type of the <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination /// endpoint. /// </typeparam> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound <TMessage, TRouter>( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder) where TRouter : IOutboundRouter <TMessage> { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); return(endpointsConfigurationBuilder.AddOutbound(typeof(TMessage), typeof(TRouter))); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <typeparam name="TMessage"> /// The type of the messages to be published to this endpoint. /// </typeparam> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound <TMessage>( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IOutboundRouter <TMessage> router) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(router, nameof(router)); return(endpointsConfigurationBuilder.AddOutbound(typeof(TMessage), router)); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="endpoints"> /// The collection of <see cref="IProducerEndpoint" /> representing the destination topics or queues. /// </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, params IProducerEndpoint[] endpoints) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoints, nameof(endpoints)); return(endpointsConfigurationBuilder.AddOutbound(typeof(TMessage), endpoints)); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="endpoints"> /// The collection of <see cref="IProducerEndpoint" /> representing the destination topics or queues. /// </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, IEnumerable <IProducerEndpoint> endpoints, bool preloadProducers = true) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoints, nameof(endpoints)); return(endpointsConfigurationBuilder.AddOutbound(typeof(TMessage), endpoints, preloadProducers)); }
public void Apply(IEndpointsConfigurationBuilder builder) { foreach (var inbound in Inbound) { builder.AddInbound(inbound.Endpoint, inbound.ConnectorType, b => inbound.ErrorPolicies.Any() ? b.Chain(inbound.ErrorPolicies) : null); } foreach (var outbound in Outbound) { builder.AddOutbound(outbound.MessageType, outbound.Endpoint, outbound.ConnectorType); } }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="endpoints"> /// The endpoints (topics). /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IEnumerable <IProducerEndpoint> endpoints) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(endpoints, nameof(endpoints)); return(endpointsConfigurationBuilder.AddOutbound( messageType, new StaticOutboundRouter(endpoints))); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="endpoints"> /// The collection of <see cref="IProducerEndpoint" /> representing the destination topics or queues. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, params IProducerEndpoint[] endpoints) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(messageType, nameof(messageType)); Check.NotNull(endpoints, nameof(endpoints)); return(endpointsConfigurationBuilder.AddOutbound( messageType, (IEnumerable <IProducerEndpoint>)endpoints)); }
/// <summary> /// Adds the MQTT endpoints. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="mqttEndpointsBuilderAction"> /// An <see cref="Action{T}" /> that takes the <see cref="IMqttEndpointsConfigurationBuilder" />, /// configures the connection to the message broker and adds the inbound and outbound endpoints. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddMqttEndpoints( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Action <IMqttEndpointsConfigurationBuilder> mqttEndpointsBuilderAction) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(mqttEndpointsBuilderAction, nameof(mqttEndpointsBuilderAction)); var mqttEndpointsBuilder = new MqttEndpointsConfigurationBuilder(endpointsConfigurationBuilder); mqttEndpointsBuilderAction.Invoke(mqttEndpointsBuilder); return(endpointsConfigurationBuilder); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IOutboundRouter router) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(router, nameof(router)); endpointsConfigurationBuilder.GetOutboundRoutingConfiguration() .Add(messageType, _ => router); return(endpointsConfigurationBuilder); }
/// <summary> /// Adds and outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="routerType"> /// The type of the <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination /// endpoint. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, Type routerType) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); endpointsConfigurationBuilder.GetOutboundRoutingConfiguration().Add( messageType, serviceProvider => (IOutboundRouter)serviceProvider.GetRequiredService(routerType)); return(endpointsConfigurationBuilder); }
/// <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> /// Adds the Kafka endpoints. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="kafkaEndpointsBuilderAction"> /// An <see cref="Action{T}" /> that takes the <see cref="IKafkaEndpointsConfigurationBuilder" />, /// configures the connection to the message broker and adds the inbound and outbound endpoints. /// </param> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddKafkaEndpoints( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Action <IKafkaEndpointsConfigurationBuilder> kafkaEndpointsBuilderAction) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(kafkaEndpointsBuilderAction, nameof(kafkaEndpointsBuilderAction)); var kafkaEndpointsBuilder = new KafkaEndpointsConfigurationBuilder(endpointsConfigurationBuilder); kafkaEndpointsBuilderAction.Invoke(kafkaEndpointsBuilder); return(endpointsConfigurationBuilder); }
public void Configure(IEndpointsConfigurationBuilder builder) => builder .AddInbound <LoggedInboundConnector>( new RabbitQueueConsumerEndpoint("silverback-examples-events-queue") { Connection = GetConnectionConfig(), Queue = new RabbitQueueConfig { IsDurable = true, IsExclusive = false, IsAutoDeleteEnabled = false }, AcknowledgeEach = 2 }) .AddInbound <LoggedInboundConnector>( new RabbitExchangeConsumerEndpoint("silverback-examples-events-fanout") { Connection = GetConnectionConfig(), QueueName = $"{_consumerGroupName}.silverback-examples-events-fanout", Queue = new RabbitQueueConfig { IsDurable = true, IsExclusive = false, IsAutoDeleteEnabled = false }, Exchange = new RabbitExchangeConfig { IsDurable = true, IsAutoDeleteEnabled = false, ExchangeType = ExchangeType.Fanout } }) .AddInbound <LoggedInboundConnector>( new RabbitExchangeConsumerEndpoint("silverback-examples-events-topic") { Connection = GetConnectionConfig(), QueueName = $"{_consumerGroupName}.silverback-examples-events-topic", RoutingKey = "interesting.*.event", Queue = new RabbitQueueConfig { IsDurable = true, IsExclusive = false, IsAutoDeleteEnabled = false }, Exchange = new RabbitExchangeConfig { IsDurable = true, IsAutoDeleteEnabled = false, ExchangeType = ExchangeType.Topic } });
public void Configure(IEndpointsConfigurationBuilder builder) { builder // Produce the messages to the samples-basic topic .AddOutbound <SampleMessage>( new KafkaProducerEndpoint("samples-basic") { // The producer only needs the bootstrap server address to be // able to connect Configuration = new KafkaProducerConfig { BootstrapServers = "PLAINTEXT://localhost:9092" } }); }
public ConfigurationReaderTests() { var services = new ServiceCollection(); services.AddSingleton(typeof(ILogger <>), typeof(NullLogger <>)); services.AddSingleton(Substitute.For <IBroker>()); services.AddScoped(s => Substitute.For <IPublisher>()); services.AddSingleton <MessageLogger>(); services.AddSingleton <MessageKeyProvider>(); _serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true }); _builder = Substitute.For <IEndpointsConfigurationBuilder>(); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddMqttEndpoints( endpoints => endpoints // Configure the client options .Configure( config => config .WithClientId("samples.binary-file.consumer") .ConnectViaTcp("localhost")) // Consume the samples-binary-file-streaming topic .AddInbound( endpoint => endpoint .ConsumeFrom("samples/binary-files") .WithQualityOfServiceLevel( MqttQualityOfServiceLevel.AtLeastOnce) // Force the consumer to use the // BinaryFileMessageSerializer: this is not strictly // necessary when the messages are produced by // Silverback but it increases the interoperability, // since it doesn't have to rely on the // 'x-message-type' header value to switch to the // BinaryFileMessageSerializer. // // In this example the BinaryFileMessageSerializer is // also set to return a CustomBinaryFileMessage // instead of the normal BinaryFileMessage. This is // only needed because we want to read the custom // 'x-message-filename' header, otherwise // 'ConsumeBinaryFiles()' would work perfectly fine // (returning a basic BinaryFileMessage, without the // extra properties). .ConsumeBinaryFiles( serializer => serializer .UseModel <CustomBinaryFileMessage>()) // Retry each chunks sequence 5 times in case of an // exception .OnError(policy => policy.Retry(5)))); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddMqttEndpoints( endpoints => endpoints // Configure the client options .Configure( config => config .WithClientId("samples.binary-file.producer") .ConnectViaTcp("localhost")) // Produce the binary files to the // samples-binary-file-streaming topic .AddOutbound <BinaryFileMessage>( endpoint => endpoint .ProduceTo("samples/binary-files") .WithQualityOfServiceLevel( MqttQualityOfServiceLevel.AtLeastOnce))); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddMqttEndpoints( endpoints => endpoints // Configure the client options .Configure( config => config .WithClientId("samples.basic.producer") .ConnectViaTcp("localhost")) // Produce the SampleMessage to the samples-basic topic .AddOutbound <SampleMessage>( endpoint => endpoint .ProduceTo("samples/basic") .WithQualityOfServiceLevel( MqttQualityOfServiceLevel.AtLeastOnce) .Retain())); }
public void Configure(IEndpointsConfigurationBuilder builder) { builder .AddKafkaEndpoints( endpoints => endpoints // Configure the properties needed by all consumers/producers .Configure( config => { // The bootstrap server address is needed to connect config.BootstrapServers = "PLAINTEXT://localhost:9092"; }) // Produce the SampleMessage to the samples-batch topic .AddOutbound <SampleMessage>( endpoint => endpoint .ProduceTo("samples-batch"))); }
/// <summary> /// Adds an outbound endpoint for the specified message type. /// </summary> /// <param name="endpointsConfigurationBuilder"> /// The <see cref="IEndpointsConfigurationBuilder" />. /// </param> /// <param name="messageType"> /// The type of the messages to be published to this endpoint. /// </param> /// <param name="router"> /// The <see cref="IOutboundRouter{TMessage}" /> to be used to determine the destination endpoint. /// </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> /// <returns> /// The <see cref="IEndpointsConfigurationBuilder" /> so that additional calls can be chained. /// </returns> public static IEndpointsConfigurationBuilder AddOutbound( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, Type messageType, IOutboundRouter router, bool preloadProducers = true) { Check.NotNull(endpointsConfigurationBuilder, nameof(endpointsConfigurationBuilder)); Check.NotNull(messageType, nameof(messageType)); Check.NotNull(router, nameof(router)); endpointsConfigurationBuilder.GetOutboundRoutingConfiguration() .Add(messageType, _ => router); if (preloadProducers) { PreloadProducers(router, endpointsConfigurationBuilder.ServiceProvider); } return(endpointsConfigurationBuilder); }
public void Configure(IEndpointsConfigurationBuilder builder) { // Consume the samples-basic topic builder.AddInbound( new KafkaConsumerEndpoint("samples-basic") { Configuration = new KafkaConsumerConfig { // The consumer needs at least the bootstrap server address // and a group id to be able to connect BootstrapServers = "PLAINTEXT://localhost:9092", GroupId = "sample-consumer", // AutoOffsetReset.Earliest means that the consumer must start // consuming from the beginning of the topic, if no offset was // stored for this consumer group AutoOffsetReset = AutoOffsetReset.Earliest } }); }
private static IEnumerable <IProducerEndpoint> FilterRegisteredEndpoints( this IEndpointsConfigurationBuilder endpointsConfigurationBuilder, IEnumerable <IProducerEndpoint> endpoints, Type messageType) { var endpointsToRegister = new List <IProducerEndpoint>(); var registeredStaticEndpoints = endpointsConfigurationBuilder .GetOutboundRoutingConfiguration() .Routes.Where(route => route.MessageType == messageType) .Select(route => route.GetOutboundRouter(endpointsConfigurationBuilder.ServiceProvider)) .OfType <StaticOutboundRouter>() .SelectMany(router => router.Endpoints) .ToList(); foreach (var endpoint in endpoints) { // There can only be one matching already registered endpoint. // Because when that one was registered it was also checked for already // existing registrations and, thus, would not have been added. // The only way this could be broken is when a user registers a // StaticOutboundRouter with endpoints explicitly - which is unlikely // and would cause SingleOrDefault to throw. IProducerEndpoint?registeredEndpoint = registeredStaticEndpoints.SingleOrDefault(r => endpoint.Name == r.Name); if (registeredEndpoint is null) { endpointsToRegister.Add(endpoint); break; } if (!endpoint.Equals(registeredEndpoint)) { throw new EndpointConfigurationException( $"An endpoint '{endpoint.Name}' for message type '{messageType.FullName}' but with a different configuration is already registered."); } } return(endpointsToRegister); }