powershell 通过PowerShell向Service Bus队列发送和接收消息
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 通过PowerShell向Service Bus队列发送和接收消息相关的知识,希望对你有一定的参考价值。
Import-Module "PATH_TO_Microsoft.ServiceBus.dll"
#Create the required credentials
$tokenProvider = [Microsoft.ServiceBus.TokenProvider]::CreateSharedSecretTokenProvider("owner", "YOUR_ISSUERSECRET")
$namespaceUri = [Microsoft.ServiceBus.ServiceBusEnvironment]::CreateServiceUri("sb", "YOUR_NAMESPACE", "");
$namespaceManager = New-Object Microsoft.ServiceBus.NamespaceManager $namespaceUri,$tokenProvider
#Create a queue
$queue = $namespaceManager.CreateQueue("MyPowershellQueue");
#Create a message factory
$factory = [Microsoft.ServiceBus.Messaging.MessagingFactory]::Create($namespaceUri, $tokenProvider)
#Create a sender (with ReceiveAndDelete mode) and send a few messages
$sender = $factory.CreateMessageSender($queue.Path)
#Send a few messages
1..10 | ForEach-Object { $sender.Send("Message from Powershell " + [Guid]::NewGuid()) }
#Create a message receiver (with ReceiveAndDelete mode) and receive the messages
$receiver = $factory.CreateMessageReceiver($queue.Path, [Microsoft.ServiceBus.Messaging.ReceiveMode]::ReceiveAndDelete)
#Receive the messages
1..10 | ForEach-Object { Write-Output "Received " + $receiver.Receive([TimeSpan]::FromSeconds(10))}
#Close the factory
$factory.Close()
以上是关于powershell 通过PowerShell向Service Bus队列发送和接收消息的主要内容,如果未能解决你的问题,请参考以下文章
从csv读取后使用powershell向vm添加标签时出错
通过 Powershell 脚本将权限角色分配给服务主体
powershell 用于向hosts文件添加/删除/查看条目的Powershell脚本。
Powershell命令等待一段时间
使用 PowerShell 向窗口控件发送消息
Powershell追踪路由