简体   繁体   English

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

[英]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"). 我试图将消息(“ mymessage”)发布到ActiveMQ队列(“ myqueue”)。 In Powershell v3+, this is very straightforward using Invoke-WebRequest. 在Powershell v3 +中,使用Invoke-WebRequest非常简单。 Unfortunately, I am stuck with v2. 不幸的是,我坚持使用v2。 To the best of my knowledge, this is the code in Powershell v3 that I need to replicate in 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

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. 我对Powershell非常陌生,尤其是它的.NET方面。 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 . nms或.NET消息传递API库应该正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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