java的原生rabbitmq客户端允许在连接设置上设置心跳,例如:
import com.rabbitmq.client.ConnectionFactory;
...
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setAutomaticRecoveryEnabled(true);
connectionFactory.setHost("some://host");
connectionFactory.setConnectionTimeout(5000);
connectionFactory.setRequestedHeartbeat(5); // keeps an idle connection alive
Run Code Online (Sandbox Code Playgroud)
Rabbitmq客户端使用心跳设置做什么?它是否向特殊交换/队列发送存根消息或者其他什么?
有人可以详细解释一下吗?
我想要构建的是一个spring-boot(v1.2.3)应用程序,并使用SpringFox(swagger2)v2.0.0公开我的Rest API
我的Swagger Spring配置
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket myApi() {
return new Docket(DocumentationType.SWAGGER_2)
.genericModelSubstitutes(DeferredResult.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(false)
.pathMapping("/my-prj");
}
}
Run Code Online (Sandbox Code Playgroud)
我需要使用gson将我的pojo转换为json,我这样做:
@Configuration
public class GsonHttpMessageConverterConfig {
@Bean
public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) {
GsonHttpMessageConverter converter = new GsonHttpMessageConverter();
converter.setGson(gson);
return converter;
}
}
Run Code Online (Sandbox Code Playgroud)
麻烦的是,如果使用GsonHttpMessageConverter,swagger v2会生成错误的json:
{
"value": "{\"swagger\":\"2.0\",\"info\":{\"description\":\"Api Documentation\",\"version\":\"1.0\",\"title\":\"Api Documentation\",\"termsOfService\":\"urn:tos\",\"contact\":{\"name\":\"Contact Email\"},\"license\":{\"name\":\"Apache 2.0\",\"url\":\"http:
...
Run Code Online (Sandbox Code Playgroud)
JSON以value为前缀,真正的JSON成为转义字符串.
这是如果不使用它应该如何GsonHttpMessageConverter:
{
"swagger": "2.0",
"info": {
"description": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. …Run Code Online (Sandbox Code Playgroud)