使用ActiveMQ来处理webservice调用期间的错误

huangapple 未分类评论50阅读模式
英文:

Using ActiveMQ to handle errors during webservice call

问题

我有一个Java进程,它正在监听由ActiveMQ托管的队列中的消息,并在接收到状态为COMPLETE的消息时调用Web服务。

我还在考虑是否可以使用ActiveMQ来处理Web服务调用。我是否可以通过另一个队列最大程度地利用ActiveMQ?

这可能有助于我处理以下情况:如果一个或多个Web服务调用在第一次尝试时失败。但我正在思考如何实现类似这样的功能。

我需要将Web服务参数转发到ActiveMQ队列,然后寻找某些内容吗?

@Autowired
private JavaMailSender javaMailSender;

// 使用JMS 2.0的工作代码
@JmsListener(destination = "MessageProducer")
public void processBrokerQueues(String message) throws DaoException {
    ...
    if(receivedStatus.equals("COMPLETE")) {
         
        // 在COMPLETE状态下进行某些操作                  
        // 需要调用8-10个Web服务(以下仅显示2个以简洁为例)
	   
        ProcessBroker obj = new ProcessBroker();
        ProcessBroker obj1 = new ProcessBroker();
		
        // 调用Web服务 1
        try {
            System.out.println("测试 1 - 发送 Http POST 请求 #1");
            obj.sendHTTPPOST1();
        } finally {
            obj.close();            
        }
       
        // 调用Web服务 2。
        try {
            System.out.println("测试 2 - 发送 Http POST 请求 #2");
            obj1.sendHTTPPOST2();
        } finally {
            obj1.close();
        }                         
    } else {
        // 做一些其他操作
    }
}

我在寻找的是:

基本上,如果有可能创建一个附加的消息队列,将8个消息提交到队列,每个消息对应一个Web服务端点,并有一个专门用于消息队列的队列监听器。如果消息无法成功传递,它可以被放回队列以便稍后传递。

英文:

I have a Java process which is listening for messages from a queue hosted by ActiveMQ and calls webservices if received status is COMPLETE.

I was also thinking of handling webservices calls using ActiveMQ as well. Is there a way I could make best use of ActiveMQ using maybe another queue?

This might help me in handling a scenario if one or more webservice calls fails in first attempt. But I'm trying to think what could I do to achieve something like this.

Do I need to forward webservice parameters to ActiveMQ queue and then look for something?

@Autowired
private JavaMailSender javaMailSender;
         
// Working Code with JMS 2.0
@JmsListener(destination = "MessageProducer")
public void processBrokerQueues(String message) throws DaoException {
    ... 
    if(receivedStatus.equals("COMPLETE")) {
         
        // Do something inside COMPLETE                  
        // Need to call 8-10 webservices (shown only 2 below for breviety)
	   
	    ProcessBroker obj = new ProcessBroker();
        ProcessBroker obj1 = new ProcessBroker();
		
 	    // Calling webservice 1
        try {
            System.out.println("Testing 1 - Send Http POST request #1 ");
            obj.sendHTTPPOST1();
        } finally {
            obj.close();            
        }
       
	    // Calling webservice 2.
        try {
            System.out.println("Testing 2 - Send Http POST request #2");
            obj1.sendHTTPPOST2();
        } finally {
            obj1.close();
        }                         
    } else {
        // Do something
    }
}

What I'm looking for:

Basically If there is a possibility of creating an additional message queue, submit 8 messages to the queue, one corresponding to each webservice end point and have a queue listener dedicated to the message queue. If the message could not be delivered successfully, it could be put back on the queue for later delivery.

huangapple
  • 本文由 发表于 2020年5月29日 23:08:01
  • 转载请务必保留本文链接:https://java.coder-hub.com/62089060.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定