jersey rest web Service with Activemq middleware integration

匿名 (未验证) 提交于 2019-12-03 01:10:02

问题:

I have a Restful service API developed with JAX-RS and jersey. I have deployed the same in TOMCAT 7. Now I would like to implement Activemq so that I would keep all request in a queue and process the request resource. How to do this and integrate with tomcat7. How to integrate ActiveMq with Tomcat7 or my rest service webapp. How to call the service.

Important :- Inside the Rest Api, I am using FilterChaining concept for security concern and after verification of the calling party, I am simply forwarding the request to the resource. For this I have added in web.xml.

Thanks

Here is my class :-

    public class LimitFilter implements Filter {          public void doFilter(ServletRequest request, ServletResponse response,                 FilterChain chain) throws IOException, ServletException {  //some authentication                 if (true) {                     // let the request through and process as usual                     chain.doFilter(request, response);                  } else {                     // handle limit case, e.g. return status code 429 (Too Many                     // Requests)                     // see http://tools.ietf.org/html/rfc6585#page-3                     ((HttpServletResponse) response).sendError(429);                 }             }              }         }

Here is my sample class for activemq:-

public class Qservlet extends HttpServlet {      /**      *       */     private static final long serialVersionUID = 1L;      public void doGet(HttpServletRequest request, HttpServletResponse response)             throws IOException, ServletException {             String body = "";         try {             // Create a ConnectionFactory              ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin", ActiveMQConnection.DEFAULT_BROKER_URL);              // Create a Connection              Connection connection = connectionFactory.createConnection();               Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);              Destination destination = session.createQueue("testQ");              TextMessage message = session.createTextMessage();             message.setText( "My text message was send and received");//             message.setJMSRedelivered(true);             message.setJMSCorrelationID(request.getSession().getId());              connection.start();              MessageProducer producer = session.createProducer(destination);             producer.setDeliveryMode(DeliveryMode.PERSISTENT);             producer.send(message);              message = null;             MessageConsumer consumer = session.createConsumer(destination);             message = (TextMessage) consumer.receive(1000);             if (message != null) {                 body = message.getText();             }               producer.close();             consumer.close();             session.close();             connection.close();          } catch (Exception e) {             System.out.println(e.toString());         }      }  }

Now if any request is coming in Limit Filter class, I am forwarding directly to the resources after some authentication mecanisam. Thats why I am using filter concept for catching all request.

Second class is example class when i am running ; messaging is enquing and dequeueing; I can see in console for ActiveMq.

In the first class I am simply writing "chain.doFilter(request, response)" to forward all http request to the respective resource. Now How to do here. Where to put the HTTP request. I need to handle each request asynchronously. REST is synchronous.

Please suggest some way. and explain your answer.

Thanks/Regards Kumar Shorav

回答1:

Have you seen the REST documentation at Apache ActiveMQ: http://activemq.apache.org/rest.html

Also are you talking about embedding ActiveMQ as a broker inside Tomcat, or do you run ActiveMQ broker in a seperate box/jvm?

As the standalone ActiveMQ has REST API out of the box, as stated in that link above.



回答2:

please refer : http://java.dzone.com/articles/jms-activemq

its solve

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!