【问题标题】:ActiveMQ Handling Messages thru RESTActiveMQ 通过 REST 处理消息
【发布时间】:2016-04-14 23:27:58
【问题描述】:

我是 ActiveMQ 的新手,我们在其他位置有一个 ActiveMQ 服务器,我们无法通过 tcp 套接字连接,但能够使用 REST 命令获取消息

http://admin:admin@localhost:8161/api/message?destination=queue://orders.input

我在 ActiveMQ 中有 99K+ 消息,需要使用 REST 命令消费并需要存储在文本文件中,

import static com.jayway.restassured.RestAssured.given;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.dnb.e2e.automation.util.CommonUtil;
import com.dnb.e2e.automation.util.WebServiceUtil;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.config.SSLConfig;
import com.jayway.restassured.config.SessionConfig;
import com.jayway.restassured.response.Headers;
public class MQwithRest {
     public static String getResponse() throws Exception 
     {
        String url = "http://admin:admin@localhost:8161/api/message?destination=queue://SAMPLEQUEUE";

        String response = "a";

            while(response!=""){
            try {
                response =  given().header("content-type", "application/json")
                        .request()
                        .config(RestAssured.config().sslConfig(new SSLConfig().allowAllHostnames()))
                        .when().get(url).asString();
                System.out.println(response);
            } catch (Exception e) {
                e.printStackTrace();
            }
            }
            return "empty";
        }

     public static void main(String args[]) throws Exception
     {
                 System.out.println(MQwithRest.getResponse());
     }
}

在上面的代码中,我在输出端显示消费消息。当我通过休息实现时,我每次会话一次只能使用一条消息。

任何机构都可以帮助使用 REST 服务在单个会话中使用 99k+ 消息吗?

【问题讨论】:

    标签: java rest activemq


    【解决方案1】:

    您也可以通过隧道JMS client over HTTP。 这样,您就可以绕过网络中的任何非 HTTP 限制,并且仍然使用 JMS 术语。

    使用捆绑的其余网络应用程序,您在检索消息的语义方面有点受限。无论如何,无论如何,您应该能够使用纯 HTTP/Rest 获取所有消息。只需使用循环来获取消息。

    【讨论】:

    • 谢谢@Petter Nordander
    猜你喜欢
    • 2019-06-02
    • 2023-04-02
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    • 2019-02-14
    • 1970-01-01
    相关资源
    最近更新 更多