Search in sources :

Example 1 with MessageConsumer

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

the class StandardMessagingBuilder method buildConsumer.

/**
 * buildConsumer
 *
 * @param groupName
 * @param msgType
 * @param queueType
 * @return
 */
public MessageConsumer buildConsumer(String groupName, String msgType, MQFactory.QueueType queueType) {
    String ConsumeThreadMax = ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".consumethreadmax");
    String ConsumeStopInterval = ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".consumestopinterval");
    boolean check = DataConvertHelper.toBoolean(ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".enable"), false);
    if (check == false) {
        return null;
    }
    String[] bizIDs = new String[1];
    bizIDs[0] = msgType;
    MessageConsumer consumer = MessagingFactory.createMessageConsumer(groupName, bizIDs, ConsumeThreadMax == null ? 10 : Integer.parseInt(ConsumeThreadMax), ConsumeStopInterval == null ? 0 : Long.parseLong(ConsumeStopInterval), queueType);
    return consumer;
}
Also used : MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer)

Example 2 with MessageConsumer

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

the class GatherDataManager method start.

@Override
public void start() {
    StandardMessagingBuilder builder = new StandardMessagingBuilder("GatherDataManagerMessageBuilder", feature);
    try {
        builder.init();
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, GatherDataManager can not START", e);
        return;
    }
    String[] topics = getConfigManager().getFeatureConfiguration(feature, "topics").split(",");
    List<MessageHandler> handlers = new ArrayList<>();
    for (String topic : topics) {
        handlers.add(new DefaultGatherDataHandler(topic));
    }
    MessagingContext.putConsumerHandlers(handlers);
    // init consumers
    consumers = new ArrayList<>();
    for (String topic : topics) {
        MessageConsumer consumer = builder.buildConsumer(topic);
        if (consumer == null) {
            continue;
        }
        consumers.add(consumer);
    }
    // start all consumers
    for (MessageConsumer consumer : consumers) {
        consumer.start();
        log.info(this, "GatherData Consumer [" + consumer.getName() + "] start");
    }
    log.info(this, "GatherDataManager start");
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer) MessageHandler(com.creditease.uav.messaging.api.MessageHandler) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DefaultGatherDataHandler(com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)

Example 3 with MessageConsumer

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

the class GatherDataManager method stop.

@Override
public void stop() {
    for (MessageConsumer consumer : consumers) {
        consumer.shutdown();
        log.info(this, "GatherData Consumer [" + consumer.getName() + "] shutdown");
    }
    log.info(this, "GatherDataManager stop");
}
Also used : MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer)

Example 4 with MessageConsumer

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

the class TestRMQMessageConsumer 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);
    String[] bizIDs = new String[1];
    bizIDs[0] = "test";
    String[] handlerNames = new String[1];
    handlerNames[0] = "test";
    MessageConsumer consumer = MessagingFactory.createMessageConsumer("name", bizIDs, 10, 0);
    consumer.start();
}
Also used : MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer) HashMap(java.util.HashMap)

Example 5 with MessageConsumer

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

the class StandardMessagingBuilder method buildConsumer.

/**
 * build comsumer by msgtype
 */
public MessageConsumer buildConsumer(String msgType, MQFactory.QueueType queueType) {
    String ConsumeThreadMax = ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".consumethreadmax");
    String ConsumeStopInterval = ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".consumestopinterval");
    boolean check = DataConvertHelper.toBoolean(ConfigurationManager.getInstance().getFeatureConfiguration(feature, msgType + ".enable"), true);
    if (check == false) {
        return null;
    }
    String[] bizIDs = new String[1];
    bizIDs[0] = msgType;
    MessageConsumer consumer = MessagingFactory.createMessageConsumer(msgType, bizIDs, ConsumeThreadMax == null ? 10 : Integer.parseInt(ConsumeThreadMax), ConsumeStopInterval == null ? 0 : Long.parseLong(ConsumeStopInterval), queueType);
    return consumer;
}
Also used : MessageConsumer(com.creditease.uav.messaging.api.MessageConsumer)

Aggregations

MessageConsumer (com.creditease.uav.messaging.api.MessageConsumer)5 DefaultGatherDataHandler (com.creditease.uav.collect.server.messaging.DefaultGatherDataHandler)1 MessageHandler (com.creditease.uav.messaging.api.MessageHandler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 StandardMessagingBuilder (org.uavstack.resources.common.messaging.StandardMessagingBuilder)1