Skip to content

vlariono/PSAsbUtils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PSAsbUtils

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 to ServiceBus namespace

  1. Connect with powershell credentials
Connect-AzAccount
$connection = Connect-AsbNamespace -Namespace <namespace>.servicebus.windows.net
  1. Connect with connection string
$connection = Connect-AsbNamespace -ConnectionString '<connection string>'
  1. List active connections
Get-AsbNamespaceConnection
  1. Set default service bus connection. Allows to skip Connection parameter
Connect-AsbNamespace -Namespace <namespace>.servicebus.windows.net|Set-AsbDefaultConnection

or

Set-AsbDefaultConnection -Connection $connection

Receive messages from a queue

  1. Peek messages from a queue
Get-AsbMessage -Connection $connection -QueueName <queue>
  1. Receive message from q queue
$messages = Receive-AsbMessage -Connection $connection -QueueName <queue>
  1. Messages are received in PeekLock mode and need to be completed
$messages|Complete-AsbMessage -Connection $connection
  1. Move received message to dead letters queue (DLQ)
$messages|Kill-AsbMessage -DeadLetterReason "Some reason" -Connection $connection
  1. Unlock received message to make it available for processing
$message|Unlock-AsbMessage

Create new message

  1. Create new message
New-AsbMessage -Body '123456'
  1. 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

  1. Send message to a queue
Send-AsbMessage -Connection $connection -Message $message
New-AsbMessage -Body '1234567'|Send-AsbMessage -Connection $connection -QueueName <queue>

Disconnect from service bus namespace

  1. Close single connection
Disconnect-AsbNamespace -Connection $connection

About

Azure ServiceBus message module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published