简体   繁体   中英

How can I post a message to an ActiveMQ queue using Powershell 2.0?

I am trying to post a message ("mymessage") to an ActiveMQ queue ("myqueue"). In Powershell v3+, this is very straightforward using Invoke-WebRequest. Unfortunately, I am stuck with v2. To the best of my knowledge, this is the code in Powershell v3 that I need to replicate in v2:

$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

My current attempt looks like this:

$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

As you can see, I haven't made much progress. I'm very new to Powershell, and especially the .NET aspect of it. Any help would be greatly appreciated.

I know it's been a long time since this question was asked, but have you looked at this ?

The nms or, .NET messaging API library should work .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM