Search in sources :

Example 1 with Message

use of com.creditease.uav.messaging.api.Message in project uavstack by uavorg.

the class AppServerLogPublishWorker method handle.

@Override
protected void handle(List<MonitorDataFrame> mdflist) {
    MessageProducer producer = (MessageProducer) this.getComponentResource("messageproducer", "MessageProducerResourceComponent");
    // submit profile data
    Message msg = MessagingFactory.createMessage(MonitorDataFrame.MessageType.Log.toString());
    StringBuilder sb = new StringBuilder("[");
    for (MonitorDataFrame mdf : mdflist) {
        sb.append(mdf.toJSONString() + ",");
    }
    if (mdflist.size() > 0) {
        sb = sb.deleteCharAt(sb.length() - 1);
    }
    String stream = sb.append("]").toString();
    msg.setParam(MonitorDataFrame.MessageType.Log.toString(), stream);
    if (log.isDebugEnable()) {
        log.debug(this, "## LogPublishWorker stream length ## : " + stream.getBytes().length);
        log.debug(this, "## LogPublishWorker stream value ## : " + stream);
    }
    producer.setLogger(log);
    boolean check = producer.submit(msg);
    String sendState = "Log Data Sent " + (check ? "SUCCESS" : "FAIL");
    if (log.isDebugEnable()) {
        log.debug(this, sendState + " " + sendState);
    }
    if (null != getConfigManager().getComponent("monitortestagent", "MonitorAgentUT")) {
        AgentFeatureComponent afc = (AgentFeatureComponent) this.getConfigManager().getComponent("monitortestagent", "monitortestagent");
        afc.exchange("logTest", mdflist);
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) MessageProducer(com.creditease.uav.messaging.api.MessageProducer) MonitorDataFrame(com.creditease.agent.monitor.api.MonitorDataFrame) AgentFeatureComponent(com.creditease.agent.spi.AgentFeatureComponent)

Example 2 with Message

use of com.creditease.uav.messaging.api.Message in project uavstack by uavorg.

the class DataCollector method submit.

public void submit(CollectDataFrame frame) {
    if (log.isDebugEnable()) {
        log.debug(this, String.format("submit frame: time=%s, ip=%s, target=%s, action=%s, file=%s, lines=%s, eof=%s", frame.getTime(), frame.getIp(), frame.getTarget(), frame.getAction(), frame.getFile(), frame.getLines().size(), frame.isEof()));
    }
    MessageProducer producer = (MessageProducer) getComponentResource("messageproducer", "MessageProducerResourceComponent");
    CollectTask task = tasks.get(genId(frame.getTarget(), frame.getAction()));
    if (task == null) {
        if (log.isDebugEnable()) {
            log.debug(this, "??? NO task");
        }
        return;
    }
    if (task.isEofOccur() && task.hasEofEvent()) {
        onEof(task);
        frame.setEof(true);
    }
    Message msg = MessagingFactory.createMessage(task.getTopic());
    msg.setParam(task.getTopic(), "[" + frame.toJSONString() + "]");
    boolean result = producer.submit(msg);
    if (!result) {
        String detail = log.isDebugEnable() ? "\n" + msg.toJSONString() : "";
        log.warn(this, "collect data sent FAILED. " + detail);
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) MessageProducer(com.creditease.uav.messaging.api.MessageProducer)

Example 3 with Message

use of com.creditease.uav.messaging.api.Message in project uavstack by uavorg.

the class NodeInfoWatcher method sendToMQ.

private void sendToMQ(List<Map<String, Object>> mdfList) {
    AgentResourceComponent arc = (AgentResourceComponent) ConfigurationManager.getInstance().getComponent("messageproducer", "MessageProducerResourceComponent");
    MessageProducer producer = (MessageProducer) arc.getResource();
    if (producer == null) {
        log.debug(this, "MessageProducer is null!");
        return;
    }
    List<Map<String, Object>> mdfMsg = null;
    for (Map<String, Object> mdf : mdfList) {
        mdfMsg = new ArrayList<>(1);
        mdfMsg.add(mdf);
        String mesKey = MonitorDataFrame.MessageType.NodeInfo.toString();
        Message msg = MessagingFactory.createMessage(mesKey);
        msg.setParam(mesKey, JSONHelper.toString(mdfMsg));
        boolean check = producer.submit(msg);
        String sendState = mesKey + " Data Sent " + (check ? "SUCCESS" : "FAIL");
        if (log.isDebugEnable()) {
            String mdfDetail = check ? (mdf.get("ip") + "---" + mdf.get("time")) : JSONHelper.toString(mdfMsg);
            log.debug(this, sendState + ". MDF:" + mdfDetail);
        }
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) MessageProducer(com.creditease.uav.messaging.api.MessageProducer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with Message

use of com.creditease.uav.messaging.api.Message in project uavstack by uavorg.

the class NewLogDataMessageHandler method handle.

/**
 * [ { time:1464248773620, host:"09-201211070016", ip:"127.0.0.1",
 * svrid:"F:/testenv/apache-tomcat-7.0.65---F:/testenv/apache-tomcat-7.0.65", tag:"L", frames:{ "ccsp":[ {
 * "MEId":"log", "Instances":[ { "id":"F:/testenv/apache-tomcat-7.0.65/logs/ccsp.log", "values":{ "content":[ {
 * "content":"2016-localhost-startStop-1INFORootWebApplicationContext:initializationstarted",
 * "_timestamp":"1212345678129", "_lnum" : "123" } ] } }, { "id":"/ccsp/log_error.log", "values":{ "content":[
 * {"content":"xxxxxxxxxx", "_timestamp":"1212345678129", "_lnum" : "123"} ] } } ] } ] } } ]
 */
@Override
public void handle(Message msg) {
    storeToES(msg);
    // NOW, we send out the MDF for runtime notification
    boolean needGoRuntimeNtf = DataConvertHelper.toBoolean(ConfigurationManager.getInstance().getFeatureConfiguration("newlogservice", "to.runtimentf"), true);
    if (needGoRuntimeNtf == false) {
        return;
    }
    AgentResourceComponent arc = (AgentResourceComponent) ConfigurationManager.getInstance().getComponent("messageproducer", "MessageProducerResourceComponent");
    MessageProducer producer = (MessageProducer) arc.getResource();
    if (producer != null) {
        String runtimeKey = MonitorDataFrame.MessageType.RuntimeNtf.toString();
        Message rtntfmsg = MessagingFactory.createMessage(runtimeKey);
        String dataStream = msg.getParam(this.getMsgTypeName());
        rtntfmsg.setParam(runtimeKey, dataStream);
        boolean check = producer.submit(rtntfmsg);
        String sendState = runtimeKey + " Data Sent " + (check ? "SUCCESS" : "FAIL");
        if (log.isDebugEnable()) {
            log.debug(this, sendState + "    " + dataStream);
        }
    }
}
Also used : Message(com.creditease.uav.messaging.api.Message) AgentResourceComponent(com.creditease.agent.spi.AgentResourceComponent) MessageProducer(com.creditease.uav.messaging.api.MessageProducer)

Example 5 with Message

use of com.creditease.uav.messaging.api.Message in project uavstack by uavorg.

the class TestRMQMessageProducer method main.

public static void main(String[] args) {
    Map<String, String> msgType2topicMap = new HashMap<String, String>();
    msgType2topicMap.put("test", "JQ_Sub2");
    String[] consumerHandlerClasses = "test.messaging.TestMessageHandler".split(",");
    MessagingContext.init("127.0.0.1:9876", msgType2topicMap, consumerHandlerClasses, 30L, 262000L);
    SystemLogger.init("INFO", true, 5);
    MessageProducer producer = MessagingFactory.getMessageProducer(null);
    producer.start();
    Message msg = MessagingFactory.createMessage(null, "test");
    msg.setParam("sss", "jj");
    producer.submit(msg);
}
Also used : Message(com.creditease.uav.messaging.api.Message) HashMap(java.util.HashMap) MessageProducer(com.creditease.uav.messaging.api.MessageProducer)

Aggregations

Message (com.creditease.uav.messaging.api.Message)11 MessageProducer (com.creditease.uav.messaging.api.MessageProducer)11 AgentResourceComponent (com.creditease.agent.spi.AgentResourceComponent)4 HashMap (java.util.HashMap)2 MonitorDataFrame (com.creditease.agent.monitor.api.MonitorDataFrame)1 AgentFeatureComponent (com.creditease.agent.spi.AgentFeatureComponent)1 Map (java.util.Map)1