【发布时间】: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+ 消息吗?
【问题讨论】: