【问题标题】:Artemis jolokia rest api returns no real data (Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher)Artemis jolokia rest api 没有返回真实数据 (Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher)
【发布时间】:2021-06-21 11:35:52
【问题描述】:
  • 我有一个 Artemis Broker (2.17) 在我的开发机器上运行以进行本地测试。
  • 我已从 Web 控制台提取请求以获取所有队列的名称。

当我从浏览器控制台执行请求时,我得到如下 JSON 结果:

{
    "request": {
        "mbean": "org.apache.activemq.artemis:broker=\"MyBroker\"",
        "arguments": [
            "ANYCAST"
        ],
        "type": "exec",
        "operation": "getQueueNames(java.lang.String)"
    },
    "value": [
        "DLQ",
        "ExpiryQueue"
    ],
    "timestamp": 1624274952,
    "status": 200
}

当我从我的代码中执行相同的请求时,我会得到一个非常不同的结果:

{
    "request": {
        "type": "version"
    },
    "value": {
        "agent": "1.6.2",
        "protocol": "7.2",
        "config": {
            "listenForHttpService": "true",
            "authIgnoreCerts": "false",
            "agentId": "192.168.1.41-30064-15b82644-servlet",
            "debug": "false",
            "agentType": "servlet",
            "policyLocation": "file:/C:/Artemis/MyBroker/etc//jolokia-access.xml",
            "agentContext": "/jolokia",
            "serializeException": "false",
            "mimeType": "text/plain",
            "dispatcherClasses": "org.jolokia.http.Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher",
            "authMode": "basic",
            "authMatch": "any",
            "streaming": "true",
            "canonicalNaming": "true",
            "historyMaxEntries": "10",
            "allowErrorDetails": "false",
            "allowDnsReverseLookup": "true",
            "realm": "jolokia",
            "includeStackTrace": "false",
            "mbeanQualifier": "qualifier=hawtio",
            "useRestrictorService": "false",
            "debugMaxEntries": "100"
        },
        "info": {
            "product": "jetty",
            "vendor": "Eclipse",
            "version": "9.4.27.v20200227"
        }
    },
    "timestamp": 1624274809,
    "status": 200
}

Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher 接缝很奇怪。但是在搜索这个名字时,我真的找不到任何有用的东西。此外,我在 Artemis 日志中找不到任何有用的信息。

这是我的代码:

using System;
using System.Net.Http;
using System.Text;
using System.Threading;

const String username = "admin";
const String password = "password";
var encoded = Convert.ToBase64String( Encoding.GetEncoding( "ISO-8859-1" )
                                              .GetBytes( username + ":" + password ) );
var url = "http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false";
var http = new HttpClient();
http.BaseAddress = new("http://localhost:8161/");
http.DefaultRequestHeaders.Add( "Authorization", "Basic " + encoded );
http.DefaultRequestHeaders.Add( "Origin", "http://localhost:8161/" );
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new(url),
    Content = new StringContent( "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq.artemis:broker=\\\"MyBroker\\\"\",\"operation\":\"getQueueNames(java.lang.String)\",\"arguments\":[\"ANYCAST\"]}" )
};
request.Content.Headers.ContentType = new("text/json");
var response = await http.SendAsync( request, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None );
if ( response.IsSuccessStatusCode )
{
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine( content );
}
else
    Console.WriteLine( "Request failed...." );

Console.ReadLine();
  • bootstrap.xml 中绑定设置为 0.0.0.0 应该没问题。
  • jolokia-access.xml 包含 <allow-origin>*://localhost*</allow-origin> 应该没问题,但只是为了确保我已将其替换为 <allow-origin>*</allow-origin>

我需要进行一些配置才能使其正常工作吗?

【问题讨论】:

    标签: activemq-artemis jolokia


    【解决方案1】:

    Jolokia 请求可以通过两种方式发送: 作为 HTTP GET 请求,在这种情况下,请求参数完全编码在 URL 中。或者作为 POST 请求,将请求放入 HTTP 请求正文中的 JSON 有效负载中。有关详细信息,请参阅Jolokia Protocol

    当 Jolokia 服务没有收到任何请求时,它会用服务信息来回答,即:

    {
        "request": {
            "type": "version"
        },
        "value": {
    ...
    

    使用 HTTP GET 请求请求队列名称

    curl -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker=\"MyBroker\"/getQueueNames/ANYCAST
    

    使用 HTTP POST 请求请求队列名称

    curl -X POST -H "Content-Type: application/json" -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia -d '{"type" : "EXEC", "mbean" : "org.apache.activemq.artemis:broker=\"MyBroker\"", "operation" : "getQueueNames", "arguments" : ["ANYCAST"]}'
    

    【讨论】:

    • 非常感谢。这就是问题所在……不知道我怎么会错过这么明显的东西。
    【解决方案2】:

    您的代码使用的是 HTTP GET,但它使用的是固定 URL(即http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false 和有效负载(即{"type":"exec","mbean":"org.apache.activemq.artemis:broker="MyBroker","operation":"getQueueNames(java.lang.String)","arguments":["ANYCAST"]}")。这不符合@987654321 @。

    如果您使用 HTTP GET,那么一切都应该在 URL 本身中,就像它是您的浏览器控制台一样。例如,使用这个:

    http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker="MyBroker"/getQueueNames/ANYCAST
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 1970-01-01
      • 2021-10-29
      • 2017-11-26
      • 2014-12-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多