使用AMQP进行Spring Remoting - 客户端没有看到从服务器

时间:2018-02-01 10:27:22

标签: java spring rabbitmq amqp remoting

我试图从http://www.baeldung.com/spring-remoting-amqp运行示例,即使我设置与专用vhost到RabbitMQ代理的连接,我也只能从客户端发送请求(我在RabbitMQ UI中看到它) ),但我从来没有从服务器得到答案。

服务器似乎使用getBeanDefinitionNames()来修改服务(返回的Impl类),但我肯定不会在客户端看到这些bean。我使用注释来设置bean,而不是.xml文件。

所以问题是 - 为什么我的客户端没有看到服务器bean,我发现它更多的是以下方式:

@Autowired
private ApplicationContext appContext;

public GetResponse get(String id) {
  Service service = appContext.getBean(Service.class);
  System.out.println(service.ping());
  return new GetResponse();
}

我在网络服务层面得到的答案是:

{
  "timestamp": "2018-02-01T10:09:00.809Z",
  "status": 500,
  "error": "Internal Server Error",
  "exception": "org.springframework.remoting.RemoteProxyFailureException",
  "message": "No reply received from 'toString' with arguments '[]' - perhaps a timeout in the template?",
"path": "/v3/app/r"
}

服务:

public interface Service extends Serializable{
  String ping();
}

服务Impl:

public class ServiceImpl implements Service {

@Override
public String ping() {
  System.out.println("ponged");
  return "pong";
}

@Override
public String toString() {
  return "to string";
}

EDITED + BOUNTY

在链接中,您可以找到我想要连接在一起的提取模块。我想它仍然没有看到'来自第二个模块的bean。

使用GET http://localhost:8081/v3/app/u可以解决这个问题。必须根据您的设置调整RabbitMQ设置。

https://bitbucket.org/herbatnic/springremotingexample/overview

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

3 年后偶然发现这个问题.. 试图运行 Baeldung example

我尝试调试了这个问题,据我所知,spring remoting 的 AMQP 实现中的一些内部在发送客户端消息时没有使用正确的路由密钥,这意味着有效负载到达了代理并且永远不会被放入处理队列,然后我们在客户端 5 秒后超时(默认)。

我尝试了 Syl 的另一个答案来删除routingKey,但是它似乎不允许我们在没有绑定的情况下创建绑定,即使直接在代理管理页面上创建绑定(没有路由密钥),它也不会不路由消息。

我没有设法使示例工作,但是我在fatalerrors.org 上发现了a blog post,它显示了AmqpProxyFactoryBean 的自定义实现,并且它对路由键进行了自定义处理,这个工作正常.

我已经使用对我有用的示例创建了 this gist,以防上面的博文失败。

要注意的另一件事是,在 Baeldung example 上,他们使用的是 DirectExchange,而在这里我们使用的是 TopicExchange