Browse Source

1.修改hos-broker配置文件
2.支持参数化是否启用Arbiter

Airhead 8 years ago
parent
commit
fd6c58016f

+ 10 - 3
hos-broker/src/main/java/com/yihu/hos/common/camelrouter/BrokerServerRouter.java

@ -1,16 +1,23 @@
package com.yihu.hos.common.camelrouter;
import com.yihu.hos.common.configuration.ArbiterConfiguration;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * @created Airhead 2016/8/1.
 */
//@Component
@Component
public class BrokerServerRouter extends RouteBuilder {
    @Autowired
    private ArbiterConfiguration arbiterConfiguration;
    @Override
    public void configure() throws Exception {
//        from("timer:brokerServerOnline?period={{timer.period}}")
//                .to("bean:brokerServerService?method=brokerServerOnline");
        if (arbiterConfiguration.getEnable()) {
            from("timer:brokerServerOnline?period={{hos.timer.period}}")
                    .to("bean:brokerServerService?method=brokerServerOnline");
        }
    }
}

+ 8 - 1
hos-broker/src/main/java/com/yihu/hos/common/configuration/ArbiterConfiguration.java

@ -8,10 +8,17 @@ import org.springframework.context.annotation.Configuration;
 */
@Configuration
public class ArbiterConfiguration {
    @Value("${hos.arbiter}")
    @Value("${hos.arbiter.enable}")
    private boolean enable;
    @Value("${hos.arbiter.url}")
    private String server;
    public String getServer() {
        return server;
    }
    public boolean getEnable() {
        return enable;
    }
}

+ 2 - 0
hos-broker/src/main/java/com/yihu/hos/services/BrokerServerService.java

@ -17,6 +17,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.net.InetAddress;
@ -28,6 +29,7 @@ import java.util.List;
/**
 * @created Airhead 2016/8/1.
 */
@Component("brokerServerService")
public class BrokerServerService implements DisposableBean {
    @Autowired
    private ApplicationConfiguration applicationConfiguration;

+ 7 - 2
hos-broker/src/main/java/com/yihu/hos/services/BusinessLogService.java

@ -1,13 +1,18 @@
package com.yihu.hos.services;
import org.apache.camel.*;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
 * @created Airhead 2016/8/8.
 */
@Component("businessLogService")
public class BusinessLogService {
    public void log(String log){
        System.out.println(log);
    public void log(@Headers Map headers, @OutHeaders Map outHeaders, @Properties Map properties,
                    @Body String body, @Attachments Map attachments){
        //TODO:转换成BusinessLog Save to Mongodb
        System.out.println(body);
    }
}

+ 23 - 10
hos-broker/src/main/resources/application.yml

@ -2,13 +2,21 @@ server:
  contextPath:
  port: 8099
  sessionTimeout:  300
hos:
  arbiter: http://192.168.131.38:10135
local:
  server:
    port: 8099
  application:
    name: HosBrokerServer
# the name of Camel
camel:
  springboot:
    name: HosBrokerServer
# how often to trigger the timer, must less than 30s
timer:
  period: 10000
---
spring:
  profiles: dev
@ -32,18 +40,23 @@ spring:
security:
  basic:
    enabled: false
# the name of Camel
camel:
  springboot:
    name: HosBrokerServer
hos:
  arbiter:
    enable: false
    url: http://192.168.131.38:10135
  timer:
      period: 10000
# how often to trigger the timer, must less than 30s
timer:
  period: 10000
---
spring:
  profiles: test
hos:
  arbiter:
    enable: false
    url: http://192.168.131.38:10135
  timer:
    period: 10000
---
application:
  message: EHR Browser