Azure Service Bus messaging module. The module is able to receive, send and peek Azure Service Bus messages. Dead letters are supported. It is useful with frameworks like NServiceBus when you need to resubmit a message from an error queue.
- Connect with powershell credentials
Connect-AzAccount
$connection = Connect-AsbNamespace -Namespace <namespace>.servicebus.windows.net
- Connect with connection string
$connection = Connect-AsbNamespace -ConnectionString '<connection string>'
- List active connections
Get-AsbNamespaceConnection
- Set default service bus connection. Allows to skip Connection parameter
Connect-AsbNamespace -Namespace <namespace>.servicebus.windows.net|Set-AsbDefaultConnection
or
Set-AsbDefaultConnection -Connection $connection
- Peek messages from a queue
Get-AsbMessage -Connection $connection -QueueName <queue>
- Receive message from q queue
$messages = Receive-AsbMessage -Connection $connection -QueueName <queue>
- Messages are received in PeekLock mode and need to be completed
$messages|Complete-AsbMessage -Connection $connection
- Move received message to dead letters queue (DLQ)
$messages|Kill-AsbMessage -DeadLetterReason "Some reason" -Connection $connection
- Unlock received message to make it available for processing
$message|Unlock-AsbMessage
- Create new message
New-AsbMessage -Body '123456'
- Create message from the received message
New-AsbMessage -ReceivedMessage $message -MessageId (New-Guid) -CustomProperties @{Test = '123456'}
$message|New-AsbMessage -MessageId (New-Guid) -CustomProperties @{Test = '123456'}
- Send message to a queue
Send-AsbMessage -Connection $connection -Message $message
New-AsbMessage -Body '1234567'|Send-AsbMessage -Connection $connection -QueueName <queue>
- Close single connection
Disconnect-AsbNamespace -Connection $connection