SQL Server Transport Native is a shim providing low-level access to the NServiceBus SQL Server Transport with no NServiceBus or SQL Server Transport reference required.
See Milestones for release notes.
Already a Patron? skip past this section
It is expected that all developers either become a Patron to use NServiceBusExtensions. Go to licensing FAQ
Support this project by becoming a Sponsor. The company avatar will show up here with a website link. The avatar will also be added to all GitHub repositories under the NServiceBusExtensions organization.
Thanks to all the backing developers. Support this project by becoming a patron.
toc
- https://nuget.org/packages/NServiceBus.SqlServer.Native/
- https://nuget.org/packages/NServiceBus.SqlServer.HttpPassthrough/
- https://nuget.org/packages/NServiceBus.SqlServer.Deduplication/
- Error or Audit queue handling: Allows to consume messages from error and audit queues, for example to move them to a long-term archive. NServiceBus expects to have a queue per message type, so NServiceBus endpoints are not suitable for processing error or audit queues. SQL Native allows manipulation or consumption of queues containing multiple types of messages.
- Corrupted or malformed messages: Allows to process poison messages which can't be deserialized by NServiceBus. In SQL Native message headers and body are treated as a raw string and byte array, so corrupted or malformed messages can be read and manipulated in code to correct any problems.
- Deployment or decommission: Allows to perform common operational activities, similar to operations scripts. Running installers requires starting a full endpoint. This is not always ideal during the execution of a deployment or decommission. SQL Native allows creating or deleting of queues with no running endpoint, and with significantly less code. This also makes it a better candidate for usage in deployment scripting languages like PowerShell.
- Bulk operations: SQL Native supports sending and receiving of multiple messages within a single
SQLConnection
andSQLTransaction
. - Explicit connection and transaction management: NServiceBus abstracts the
SQLConnection
andSQLTransaction
creation and management. SQL Native allows any consuming code to manage the scope and settings of both theSQLConnection
andSQLTransaction
. - Message pass through: SQL Native reduces the amount of boilerplate code and simplifies development.
Queue management for the native delayed delivery functionality.
See also SQL Server Transport - SQL statements.
The queue can be created using the following:
snippet: CreateQueue
The queue can be deleted using the following:
snippet: DeleteQueue
Sending to the main transport queue.
Sending a single message.
snippet: Send
Sending a batch of messages.
snippet: SendBatch
"Reading" a message returns the data from the database without deleting it.
Reading a single message.
snippet: Read
Reading a batch of messages.
snippet: ReadBatch
For many scenarios, it is likely to be necessary to keep track of the last message RowVersion
that was read. A lightweight implementation of the functionality is provided by RowVersionTracker
. RowVersionTracker
stores the current RowVersion
in a table containing a single column and row.
snippet: RowVersionTracker
Note that this is only one possible implementation of storing the current RowVersion
.
For scenarios where continual processing (reading and executing some code with the result) of incoming messages is required, MessageProcessingLoop
can be used.
An example use case is monitoring an error queue. Some action should be taken when a message appears in the error queue, but it should remain in that queue in case it needs to be retried.
Note that in the below snippet, the above RowVersionTracker
is used for tracking the current RowVersion
.
snippet: ProcessingLoop
"Consuming" a message returns the data from the database and also deletes that message.
Consume a single message.
snippet: Consume
Consuming a batch of messages.
snippet: ConsumeBatch
For scenarios where continual consumption (consuming and executing some code with the result) of incoming messages is required, MessageConsumingLoop
can be used.
An example use case is monitoring an audit queue. Some action should be taken when a message appears in the audit queue, and it should be purged from the queue to free up the storage space.
snippet: ConsumeLoop
Queue management for the native delayed delivery functionality.
See also SQL Server Transport - SQL statements.
The queue can be created using the following:
snippet: CreateDelayedQueue
The queue can be deleted using the following:
snippet: DeleteDelayedQueue
Sending a single message.
snippet: SendDelayed
Sending a batch of messages.
snippet: SendDelayedBatch
"Reading" a message returns the data from the database without deleting it.
Reading a single message.
snippet: ReadDelayed
Reading a batch of messages.
snippet: ReadDelayedBatch
"Consuming" a message returns the data from the database and also deletes that message.
Consume a single message.
snippet: ConsumeDelayed
Consuming a batch of messages.
snippet: ConsumeDelayedBatch
There is a headers helpers class NServiceBus.Transport.SqlServerNative.Headers
.
It contains several header related utilities.
Queue management for the native publish subscribe functionality.
The table can be created using the following:
snippet: CreateSubscriptionTable
The table can be deleted using the following:
snippet: DeleteSubscriptionTable
Some scenarios, such as HTTP message pass through, require message deduplication.
The table can be created using the following:
snippet: CreateDeduplicationTable
The table can be deleted using the following:
snippet: DeleteDeduplicationTable
Sending to the main transport queue with deduplication.
Sending a single message with deduplication.
snippet: SendWithDeduplication
Sending a batch of messages with deduplication.
snippet: SendBatchWithDeduplication
Deduplication records need to live for a period of time after the initial corresponding message has been send. In this way an subsequent message, with the same message id, can be ignored. This necessitates a periodic cleanup process of deduplication records. This is achieved by using DeduplicationCleanerJob
:
At application startup, start an instance of DeduplicationCleanerJob
.
snippet: DeduplicationCleanerJobStart
Then at application shutdown stop the instance.
snippet: DeduplicationCleanerJobStop
Serialize a Dictionary<string, string>
to a JSON string.
snippet: Serialize
Deserialize a JSON string to a Dictionary<string, string>
.
snippet: Deserialize
Contains all the string constants copied from NServiceBus.Headers
.
A copy of the timestamp format methods ToWireFormattedString
and ToUtcDateTime
.
The APIs of this extension target either a SQLConnection
and SQLTransaction
. Given that in configuration those values are often expressed as a connection string, ConnectionHelpers
supports converting that string to a SQLConnection
or SQLTransaction
. It provides two methods OpenConnection
and BeginTransaction
with the effective implementation of those methods being:
snippet: ConnectionHelpers
SQL HTTP Passthrough provides a bridge between an HTTP stream (via JavaScript on a web page) and the SQL Server transport.
Spear designed by Aldric Rodríguez from The Noun Project.