Class MqttProducer
Produces the messages to an endpoint.
Inherited Members
Namespace: Silverback.Messaging.Broker
Assembly: Silverback.Integration.MQTT.dll
Syntax
public sealed class MqttProducer : Producer, IProducer, IDisposable
Constructors
MqttProducer(string, IMqttClientWrapper, MqttClientConfiguration, IBrokerBehaviorsProvider<IProducerBehavior>, IServiceProvider, ISilverbackLogger<MqttProducer>)
Initializes a new instance of the MqttProducer class.
Declaration
public MqttProducer(string name, IMqttClientWrapper client, MqttClientConfiguration configuration, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IServiceProvider serviceProvider, ISilverbackLogger<MqttProducer> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The producer identifier. |
| IMqttClientWrapper | client | The IMqttClientWrapper. |
| MqttClientConfiguration | configuration | The configuration containing only the actual endpoint. |
| IBrokerBehaviorsProvider<IProducerBehavior> | behaviorsProvider | |
| IServiceProvider | serviceProvider | The IServiceProvider to be used to resolve the required services. |
| ISilverbackLogger<MqttProducer> | logger |
Properties
Client
Gets the related IBrokerClient.
Declaration
public IMqttClientWrapper Client { get; }
Property Value
| Type | Description |
|---|---|
| IMqttClientWrapper |
Configuration
Gets the producer configuration.
Declaration
public MqttClientConfiguration Configuration { get; }
Property Value
| Type | Description |
|---|---|
| MqttClientConfiguration |
EndpointConfiguration
Gets the endpoint configuration.
Declaration
public MqttProducerEndpointConfiguration EndpointConfiguration { get; }
Property Value
| Type | Description |
|---|---|
| MqttProducerEndpointConfiguration |
Methods
ProduceCore(IOutboundEnvelope)
Publishes the specified message and returns its identifier.
Declaration
protected override IBrokerMessageIdentifier? ProduceCore(IOutboundEnvelope envelope)
Parameters
| Type | Name | Description |
|---|---|---|
| IOutboundEnvelope | envelope | The envelope containing the message to be produced. |
Returns
| Type | Description |
|---|---|
| IBrokerMessageIdentifier | The message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
ProduceCoreAsync(IOutboundEnvelope, CancellationToken)
Publishes the specified message and returns its identifier.
Declaration
protected override ValueTask<IBrokerMessageIdentifier?> ProduceCoreAsync(IOutboundEnvelope envelope, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| IOutboundEnvelope | envelope | The envelope containing the message to be produced. |
| CancellationToken | cancellationToken | The cancellation token that can be used to cancel the operation. |
Returns
| Type | Description |
|---|---|
| ValueTask<IBrokerMessageIdentifier> | A ValueTask<TResult> representing the asynchronous operation. The task result contains the message identifier assigned by the broker (the Kafka offset or similar). |
Overrides
ProduceCore<TState>(IOutboundEnvelope, Action<IBrokerMessageIdentifier?, TState>, Action<Exception, TState>, TState)
Publishes the specified message and returns its identifier.
Declaration
protected override void ProduceCore<TState>(IOutboundEnvelope envelope, Action<IBrokerMessageIdentifier?, TState> onSuccess, Action<Exception, TState> onError, TState state)
Parameters
| Type | Name | Description |
|---|---|---|
| IOutboundEnvelope | envelope | The envelope containing the message to be produced. |
| Action<IBrokerMessageIdentifier, TState> | onSuccess | The callback to be invoked when the message is successfully produced. |
| Action<Exception, TState> | onError | The callback to be invoked when the produce fails. |
| TState | state | The state object that will be passed to the callbacks. |
Type Parameters
| Name | Description |
|---|---|
| TState | The type of the state object that will be passed to the callbacks. |
Overrides
Remarks
In this implementation, the message is synchronously enqueued but produced asynchronously. The callbacks are called when the message is actually produced (or the produce failed).