ActiveMQ 通过 REST 处理消息
ActiveMQ Handling Messages thru REST
我是 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+ 消息吗?
您也可以隧道 JMS client over HTTP。
这样,您就可以绕过网络中的任何 non-HTTP 限制并仍然使用 JMS 术语。
使用捆绑的其余 Web 应用程序,您在检索消息的语义方面有点受限。无论如何,无论如何,您应该能够使用纯 HTTP/Rest 获取所有消息。只需使用循环即可获取消息。
我是 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+ 消息吗?
您也可以隧道 JMS client over HTTP。 这样,您就可以绕过网络中的任何 non-HTTP 限制并仍然使用 JMS 术语。
使用捆绑的其余 Web 应用程序,您在检索消息的语义方面有点受限。无论如何,无论如何,您应该能够使用纯 HTTP/Rest 获取所有消息。只需使用循环即可获取消息。