Class Broker<TProducerEndpoint, TConsumerEndpoint>
The base class for all IBroker implementations.
Inheritance
Inherited Members
Namespace: Silverback.Messaging.Broker
Assembly: Silverback.Integration.dll
Syntax
public abstract class Broker<TProducerEndpoint, TConsumerEndpoint> : IBroker, IDisposable where TProducerEndpoint : IProducerEndpoint where TConsumerEndpoint : IConsumerEndpoint
Type Parameters
Name | Description |
---|---|
TProducerEndpoint | The type of the IProducerEndpoint that is being handled by this broker implementation. |
TConsumerEndpoint | The type of the IConsumerEndpoint that is being handled by this broker implementation. |
Constructors
| Improve this doc View sourceBroker(IServiceProvider)
Initializes a new instance of the Broker<TProducerEndpoint, TConsumerEndpoint> class.
Declaration
protected Broker(IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | serviceProvider | The IServiceProvider to be used to resolve the required services. |
Properties
| Improve this doc View sourceConsumerEndpointType
Gets the type of the IConsumerEndpoint that is being handled by this broker implementation.
Declaration
public Type ConsumerEndpointType { get; }
Property Value
Type | Description |
---|---|
Type |
Consumers
Gets the collection of IConsumer that have been created so far.
Declaration
public IReadOnlyList<IConsumer> Consumers { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IConsumer> |
IsConnected
Gets a value indicating whether this broker is currently connected.
Declaration
public bool IsConnected { get; }
Property Value
Type | Description |
---|---|
bool |
ProducerEndpointType
Gets the type of the IProducerEndpoint that is being handled by this broker implementation.
Declaration
public Type ProducerEndpointType { get; }
Property Value
Type | Description |
---|---|
Type |
Producers
Gets the collection of IProducer that have been created so far.
Declaration
public IReadOnlyList<IProducer> Producers { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<IProducer> |
Methods
| Improve this doc View sourceAddConsumer(IConsumerEndpoint)
Adds an IConsumer that will consume from the specified endpoint as soon as the broker is connected. The received messages will be forwarded to the specified callback delegate.
Declaration
public virtual IConsumer AddConsumer(IConsumerEndpoint endpoint)
Parameters
Type | Name | Description |
---|---|---|
IConsumerEndpoint | endpoint | The source endpoint. |
Returns
Type | Description |
---|---|
IConsumer | The IConsumer for the specified endpoint. |
ConnectAsync()
Connect to the message broker to start consuming.
Declaration
public Task ConnectAsync()
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
ConnectAsync(IReadOnlyCollection<IProducer>, IReadOnlyCollection<IConsumer>)
Connects all the consumers and starts consuming.
Declaration
protected virtual Task ConnectAsync(IReadOnlyCollection<IProducer> producers, IReadOnlyCollection<IConsumer> consumers)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCollection<IProducer> | producers | The producers to be connected. |
IReadOnlyCollection<IConsumer> | consumers | The consumers to be connected and started. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
DisconnectAsync()
Disconnect from the message broker to stop consuming.
Declaration
public Task DisconnectAsync()
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
DisconnectAsync(IReadOnlyCollection<IProducer>, IReadOnlyCollection<IConsumer>)
Disconnects all the consumers and stops consuming.
Declaration
protected virtual Task DisconnectAsync(IReadOnlyCollection<IProducer> producers, IReadOnlyCollection<IConsumer> consumers)
Parameters
Type | Name | Description |
---|---|---|
IReadOnlyCollection<IProducer> | producers | The producers to be disconnected. |
IReadOnlyCollection<IConsumer> | consumers | The consumers to be stopped and disconnected. |
Returns
Type | Description |
---|---|
Task | A Task representing the asynchronous operation. |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
Dispose(bool)
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | A value indicating whether the method has been called by the |
GetProducer(IProducerEndpoint)
Returns an IProducer to be used to produce to the specified endpoint.
Declaration
public virtual IProducer GetProducer(IProducerEndpoint endpoint)
Parameters
Type | Name | Description |
---|---|---|
IProducerEndpoint | endpoint | The target endpoint. |
Returns
Type | Description |
---|---|
IProducer | The IProducer for the specified endpoint. |
GetProducer(string)
Returns an IProducer to be used to produce to the specified endpoint.
Declaration
public virtual IProducer GetProducer(string endpointName)
Parameters
Type | Name | Description |
---|---|---|
string | endpointName | The target endpoint name (or friendly name). |
Returns
Type | Description |
---|---|
IProducer | The IProducer for the specified endpoint. |
InstantiateConsumer(TConsumerEndpoint, IBrokerBehaviorsProvider<IConsumerBehavior>, IServiceProvider)
Returns a new instance of IConsumer to subscribe to the specified endpoint.
Declaration
protected abstract IConsumer InstantiateConsumer(TConsumerEndpoint endpoint, IBrokerBehaviorsProvider<IConsumerBehavior> behaviorsProvider, IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
TConsumerEndpoint | endpoint | The endpoint. |
IBrokerBehaviorsProvider<IConsumerBehavior> | behaviorsProvider | |
IServiceProvider | serviceProvider | The IServiceProvider instance to be used to resolve the needed types or to be forwarded to the consumer. |
Returns
Type | Description |
---|---|
IConsumer | The instantiated IConsumer. |
InstantiateProducer(TProducerEndpoint, IBrokerBehaviorsProvider<IProducerBehavior>, IServiceProvider)
Returns a new instance of IProducer to publish to the specified endpoint. The returned instance will be cached and reused for the same endpoint.
Declaration
protected abstract IProducer InstantiateProducer(TProducerEndpoint endpoint, IBrokerBehaviorsProvider<IProducerBehavior> behaviorsProvider, IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
TProducerEndpoint | endpoint | The endpoint. |
IBrokerBehaviorsProvider<IProducerBehavior> | behaviorsProvider | |
IServiceProvider | serviceProvider | The IServiceProvider instance to be used to resolve the needed types or to be forwarded to the consumer. |
Returns
Type | Description |
---|---|
IProducer | The instantiated IProducer. |