我们正在考虑为我们的微服务基础设施(编排)引入基于AMQP的方法.我们提供多种服务,比如客户服务,用户服务,文章服务等.我们计划将RabbitMQ作为我们的中央消息系统.
我正在寻找有关主题/队列等系统设计的最佳实践.一种选择是为我们系统中可能发生的每个事件创建一个消息队列,例如:
user-service.user.deleted
user-service.user.updated
user-service.user.created
...
Run Code Online (Sandbox Code Playgroud)
我认为创建数百个消息队列不是正确的方法,不是吗?
我想使用Spring和这些不错的注释,例如:
@RabbitListener(queues="user-service.user.deleted")
public void handleEvent(UserDeletedEvent event){...
Run Code Online (Sandbox Code Playgroud)
将"用户服务通知"作为一个队列,然后将所有通知发送到该队列是不是更好?我仍然想将听众只注册到所有事件的子集,那么如何解决呢?
我的第二个问题:如果我想要侦听之前未创建的队列,我将在RabbitMQ中获得异常.我知道我可以使用AmqpAdmin"声明"一个队列,但是我是否应该为每个微服务中的数百个队列执行此操作,因为到目前为止总是会发生队列创建?
我们有一个非常简单的 Spring Boot Service ( @EnableConfigServer) 在 nginx 代理后面运行。
该服务基本上可以工作,但它一直在重新启动(上下文已关闭并连续启动)。
请参阅此处的日志文件:http : //pastebin.com/GErCF5x6
设置基本上只是一个 Java 类和两个配置(bootstrap.properties 和 application.properties)。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Configuration;
/**
* Main Application, which starts the Spring Boot context
*/
@Configuration
@EnableAutoConfiguration
@EnableConfigServer
public class Application {
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
bootstrap.properties
spring.application.name = configserver
spring.cloud.config.enabled = false
encrypt.failOnError= false
encrypt.key= secret
Run Code Online (Sandbox Code Playgroud)
应用程序属性
# HTTP Configuration
server.port = 8888
# Management Configuration …Run Code Online (Sandbox Code Playgroud) 我在Spring Boot + Spring Cloud项目中使用ConfigServer.我曾经监视端点/运行状况,但由于ConfigClient在每个请求中询问ConfigServer,因此调用度量标准"/ health"非常慢.
这是因为,对于ConfigServer的每个请求,这个实际上都调用了BitBucket - >所以整个请求链都很长/慢.
有没有办法禁止检查ConfigServer是否可用?我想分别监听这个.
最棒的朋友
我有一个棘手的情况,我想从代码的角度优化.有没有办法通过Lambda/Java8表达式缩短以下方法?
// total amount of audiences
registry.register("metric.persons.total", new CachedGauge<Integer>(1,TimeUnit.MINUTES) {
@Override
protected Integer loadValue() {
return personService.findAll().size();
}
});
Run Code Online (Sandbox Code Playgroud)
CachedGauge类看起来像这样:
public abstract class CachedGauge<T> implements Gauge<T> {
protected CachedGauge(long timeout, TimeUnit timeoutUnit) {
...
}
protected abstract T loadValue();
...
}
}
Run Code Online (Sandbox Code Playgroud)
看看是否有办法真的很棒,这里棘手的部分是有一个默认的构造函数,并且类是参数化的.
最好的,周五
java ×2
spring-boot ×2
spring-cloud ×2
amqp ×1
esb ×1
lambda ×1
nginx ×1
performance ×1
rabbitmq ×1
spring-amqp ×1