我正在用rabbitMQ做一个POC并编写一个程序来添加两个数字并获得响应。
我们为从队列中检索值而编写的代码正在无限期地运行(在while循环中),并且一行(在while循环中)等待某些数据从队列中检索;直到它从队列中获得某些东西,它将不会进入while循环的下一轮。
意味着我们正在获取无限循环内的值。 我想用这个值来进行下一步处理。从循环中返回值
while (true) { QueueingConsumer.Delivery delivery1; try { delivery = consumer.nextDelivery(); //The above line waits until delivery get some value String result1 = new String(delivery1.getBody()); System.out.println("Result received-"+ result1); } catch (InterruptedException ie) { continue; } } // end while
问题是,我不能够从while循环返回值(我要运行它无限时间)。
我该怎么做,这样循环会继续,我也会得到外部循环处理的数据呢?