如何使用Powershell 2.0将消息发布到ActiveMQ队列?

时间:2015-12-11 17:30:26

标签: powershell activemq powershell-v2.0

我正在尝试将消息(“mymessage”)发布到ActiveMQ队列(“myqueue”)。在Powershell v3 +中,使用Invoke-WebRequest非常简单。不幸的是,我坚持使用v2。据我所知,这是我需要在v2中复制的Powershell v3中的代码:

$uri = "http://ACTIVEMQ-SERVER:8161/admin/sendMessage.action"

$r = Invoke-WebRequest http://ACTIVEMQ-SERVER:8161/admin/send.jsp -SessionVariable amq

$form = $r.Forms[0]

$form.fields["JMSDestination"] = "myqueue"
$form.fields["JMSPersistent"] = "true"
$form.fields["JMSText"] = "mymessage"

$r = Invoke-WebRequest -Uri $uri -WebSession $amq -Method Post -Body $form.Fields

我目前的尝试是这样的:

$uri1 = [System.Uri]'http://ACTIVEMQ-SERVER:8161/admin/sendMessage.action'
$uri2 = [System.Uri]'http://ACTIVEMQ-SERVER:8161/admin/send.jsp'

$password = ConvertTo-SecureString 'mypassword' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential('myusername',$password)

$request = [System.Net.WebRequest]::Create($uri2)
$request.method = "GET"
$request.Credentials = $credential

如你所见,我没有取得多大进展。我对Powershell很新,尤其是它的.NET方面。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我知道问这个问题已经很久了,但是你看过this了吗?

nms或.NET消息传递API库should work