浏览代码

修改log

Airhead 8 年之前
父节点
当前提交
679d1ad661

+ 21 - 1
hos-broker/pom.xml

@ -54,6 +54,12 @@
            <groupId>com.yihu.hos</groupId>
            <artifactId>hos-web-framework</artifactId>
            <version>1.3.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
@ -93,9 +99,23 @@
            <artifactId>jsch</artifactId>
            <version>0.1.53</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR6</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>

+ 22 - 34
hos-broker/src/main/java/com/yihu/hos/broker/common/log/JMSAppender.java

@ -273,41 +273,29 @@ public class JMSAppender extends AppenderSkeleton {
            return;
        }
    try {
      if (StringUtil.isEmpty(event.getMDC("camel.messageId"))) {
        return;
      }
      ObjectMessage msg = topicSession.createObjectMessage();
      String message = event.getMessage().toString();
      String routeId = StringUtil.toString(event.getMDC("camel.routeId"));
      if (message.contains("("+routeId+") log[servers:")) {
        String body = message.substring(message.indexOf("Body:") + 5);
        String code = "";
        String order = "0";
        String totalServers = message.substring(message.indexOf("log[servers:") + 13, message.indexOf(","));
        if (!totalServers.equals("0")) {
           code = message.substring(message.indexOf("code") + 6, message.indexOf(",order"));
           order = message.substring(message.indexOf("order") + 7, message.indexOf("]"));
        try {
            if (StringUtil.isEmpty(event.getMDC("camel.messageId"))) {
                return;
            }
            ObjectMessage msg = topicSession.createObjectMessage();
            String message = event.getMessage().toString();
            String body = message.substring(message.indexOf("Body:") + 5);
            Map<String, String> map = new HashMap<>();
            map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
            map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
            map.put("transactionKey", StringUtil.toString(event.getMDC("camel.transactionKey")));
            map.put("routeId", StringUtil.toString(event.getMDC("camel.routeId")));
            map.put("breadcrumbId", StringUtil.toString(event.getMDC("camel.breadcrumbId")));
            map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
            map.put("body", body);
            map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
            msg.setObject(JSONObject.fromObject(map).toString());
            topicPublisher.publish(msg);
        } catch (JMSException | RuntimeException e) {
            errorHandler.error("Could not publish message in JMSAppender [" + name + "].", e,
                    ErrorCode.GENERIC_FAILURE);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("exchangeId", StringUtil.toString(event.getMDC("camel.exchangeId")));
        map.put("correlationId", StringUtil.toString(event.getMDC("camel.correlationId")));
        map.put("transactionKey", StringUtil.toString(event.getMDC("camel.transactionKey")));
        map.put("routeId", StringUtil.toString(event.getMDC("camel.routeId")));
        map.put("breadcrumbId",StringUtil.toString(event.getMDC("camel.breadcrumbId")));
        map.put("camelContextId", StringUtil.toString(event.getMDC("camel.contextId")));
        map.put("totalServers", Integer.parseInt(totalServers));
        map.put("code", code);
        map.put("order", order);
        map.put("body", body);
        map.put("fireTimeSource", DateUtil.toStringFormatGMTTime(DateUtil.toGMTTime(event.getTimeStamp()), DateUtil.DEFAULT_TIMESTAMP_FORMAT));
        msg.setObject(JSONObject.fromObject(map).toString());
        topicPublisher.publish(msg);
      }
    } catch(JMSException | RuntimeException e) {
      errorHandler.error("Could not publish message in JMSAppender ["+name+"].", e,
			 ErrorCode.GENERIC_FAILURE);
    }
    }
    /**

+ 14 - 0
hos-camel/src/main/java/gateway/processor/GatewayProcessor.java

@ -0,0 +1,14 @@
package gateway.processor;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class GatewayProcessor implements Processor {
    public void process(Exchange exchange) throws Exception {
    }
    public String route(Exchange exchange) {
        String query = (String)exchange.getIn().getHeader(Exchange.HTTP_QUERY);
        return null;
    }
}

+ 5 - 4
hos-camel/src/main/java/gateway/route/GatewayRouteBuilder.java

@ -1,16 +1,17 @@
package proxy.route;
package gateway.route;
import gateway.processor.GatewayProcessor;
import org.apache.camel.builder.RouteBuilder;
/**
 * @author Airhead
 * @since 2017/3/10.
 */
public class ProxyRouteBuilder extends RouteBuilder {
public class GatewayRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://0.0.0.0:9999?matchOnUriPrefix=true").routeId("proxy")
        from("jetty:http://0.0.0.0:9998/api").routeId("gateway")
                .noStreamCaching()
                .to("jetty:http://192.168.1.221:10000?bridgeEndpoint=true&throwExceptionOnFailure=false");
                .dynamicRouter(method(GatewayProcessor.class, "route"));
    }
}

+ 6 - 0
hos-web-framework-dependencies/pom.xml

@ -60,6 +60,12 @@
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>