Skip to content

Latest commit

 

History

History
373 lines (164 loc) · 10.8 KB

readme.source.md

File metadata and controls

373 lines (164 loc) · 10.8 KB

NServiceBus.SqlServer.Native

Build status NuGet Status NuGet Status NuGet Status

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

Community backed

It is expected that all developers either become a Patron to use NServiceBusExtensions. Go to licensing FAQ

Sponsors

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.

Patrons

Thanks to all the backing developers. Support this project by becoming a patron.

toc

NuGet packages

Usage scenarios

  • 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 and SQLTransaction.
  • Explicit connection and transaction management: NServiceBus abstracts the SQLConnection and SQLTransaction creation and management. SQL Native allows any consuming code to manage the scope and settings of both the SQLConnection and SQLTransaction.
  • Message pass through: SQL Native reduces the amount of boilerplate code and simplifies development.

Main Queue

Queue management

Queue management for the native delayed delivery functionality.

See also SQL Server Transport - SQL statements.

Create

The queue can be created using the following:

snippet: CreateQueue

Delete

The queue can be deleted using the following:

snippet: DeleteQueue

Sending messages

Sending to the main transport queue.

Single

Sending a single message.

snippet: Send

Batch

Sending a batch of messages.

snippet: SendBatch

Reading messages

"Reading" a message returns the data from the database without deleting it.

Single

Reading a single message.

snippet: Read

Batch

Reading a batch of messages.

snippet: ReadBatch

RowVersion tracking

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.

Processing loop

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 messages

"Consuming" a message returns the data from the database and also deletes that message.

Single

Consume a single message.

snippet: Consume

Batch

Consuming a batch of messages.

snippet: ConsumeBatch

Consuming loop

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

Delayed Queue

Queue management

Queue management for the native delayed delivery functionality.

See also SQL Server Transport - SQL statements.

Create

The queue can be created using the following:

snippet: CreateDelayedQueue

Delete

The queue can be deleted using the following:

snippet: DeleteDelayedQueue

Sending messages

Single

Sending a single message.

snippet: SendDelayed

Batch

Sending a batch of messages.

snippet: SendDelayedBatch

Reading messages

"Reading" a message returns the data from the database without deleting it.

Single

Reading a single message.

snippet: ReadDelayed

Batch

Reading a batch of messages.

snippet: ReadDelayedBatch

Consuming messages

"Consuming" a message returns the data from the database and also deletes that message.

Single

Consume a single message.

snippet: ConsumeDelayed

Batch

Consuming a batch of messages.

snippet: ConsumeDelayedBatch

Headers

There is a headers helpers class NServiceBus.Transport.SqlServerNative.Headers.

It contains several header related utilities.

Subscriptions

Queue management for the native publish subscribe functionality.

Table management

Create

The table can be created using the following:

snippet: CreateSubscriptionTable

Delete

The table can be deleted using the following:

snippet: DeleteSubscriptionTable

Deduplication

Some scenarios, such as HTTP message pass through, require message deduplication.

Table management

Create

The table can be created using the following:

snippet: CreateDeduplicationTable

Delete

The table can be deleted using the following:

snippet: DeleteDeduplicationTable

Sending messages

Sending to the main transport queue with deduplication.

Single

Sending a single message with deduplication.

snippet: SendWithDeduplication

Batch

Sending a batch of messages with deduplication.

snippet: SendBatchWithDeduplication

Deduplication cleanup

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

JSON headers

Serialization

Serialize a Dictionary<string, string> to a JSON string.

snippet: Serialize

Deserialization

Deserialize a JSON string to a Dictionary<string, string>.

snippet: Deserialize

Copied header constants

Contains all the string constants copied from NServiceBus.Headers.

Duplicated timestamp functionality

A copy of the timestamp format methods ToWireFormattedString and ToUtcDateTime.

ConnectionHelpers

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

SqlServer.HttpPassthrough

SQL HTTP Passthrough provides a bridge between an HTTP stream (via JavaScript on a web page) and the SQL Server transport.

See docs/http-passthrough.md.

Icon

Spear designed by Aldric Rodríguez from The Noun Project.