如何解决使用者必须连接到兔子实例时如何处理amqp存根
我们在春季启动项目中使用Spring AMQP。
有几种微服务可以独立运行,其中一些正在使用RabbitMQ。
中有一项服务是生产者@EnableRabbit
public class RabbitConfig {
@Bean
public Jackson2JsonMessageConverter producerJackson2MessageConverter(ObjectMapper objectMapper) {
return new Jackson2JsonMessageConverter(objectMapper);
}
@Primary
@Bean
public ObjectMapper objectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new SimpleModule());
objectMapper.registerModule(new Jdk8Module());
objectMapper.registerModule(new JavaTimeModule());
objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
return objectMapper;
}
}
还有示例兔子监听器
@Slf4j
@Component
@AllArgsConstructor
@RabbitListener(queues = "example-queue")
public class RabbitListener {
private final RabbitTemplate rabbitTemplate;
@RabbitHandler
@LoggedEndpoint
public void eventListener(...) {
...
}
}
合同是
label: event.label
input:
messageFrom: event.start
messageHeaders:
contentType: application/json
__TypeId__: event.EventStart
messageBody:
some:body
outputMessage:
sentTo: event.end
headers:
contentType: application/json
__TypeId__: event.EventEnd
body:
some:body
但是在用户端是ConnectionFactory,它需要连接到正在运行的amqp实例
@Bean
public RabbitTemplate createRabbitTemplate(MessageConverter messageConverter) {
RabbitTemplate template = new RabbitTemplate(this.connectionFactory);
template.setMessageConverter(messageConverter);
return template;
}
测试类:
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc()
@Import(ServiceConfigTest.class)
@AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL,ids = "com.example:amqp:+:5672")
public class IntegrationTest{
...
}
然后的问题是,当使用者尝试连接到本地主机上的实例f.e时,java将引发错误
Caused by: java.lang.OutOfMemoryError: Java heap space
问题是:当生产者测试需要连接到正在运行的Rabbitmq实例时,或者该错误与错误的合同/存根运行程序配置有关,是否可以运行存根?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。