package org.logstashplugins; import co.elastic.logstash.api.Configuration; import co.elastic.logstash.api.Event; import org.junit.Test; import org.logstash.Timestamp; import org.logstash.plugins.ConfigurationImpl; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; public class RocketmqOutputTest { @Test public void testRocketMQOutput() { Map configValues = new HashMap<>(); configValues.put(RocketMQ.NAMESRV_ADDR.name(), "10.62.16.226:31409"); // configValues.put(RocketMQ.PRODUCER_GROUP.name(), ""); configValues.put(RocketMQ.TOPIC.name(), "logstash-output-rocketmq"); // configValues.put(RocketMQ.TAG.name(), ""); // configValues.put(RocketMQ.CODEC_NAME.name(), "json_lines"); Configuration config = new ConfigurationImpl(configValues); RocketMQ rocketmq = new RocketMQ("test-id", config, null); int eventCount = 5; Collection events = new ArrayList<>(); for (int k = 0; k < eventCount; k++) { events.add(getEvent(k)); } rocketmq.output(events); } private static Event getEvent(int index) { Event event = new org.logstash.Event(); event.setField("show", "true"); event.setField("tableName", "cons_staff"); event.setField("title", "鸿鹄" + index); event.setField("comIds", "1730762885845381120"); event.setField("buzType", "通讯录"); event.setField("url", "cons_staff&1730762885996376064"); event.setField("fromTypes", "WEB,APP"); event.setField("createTime", Timestamp.now()); event.setField("updateTime", Timestamp.now()); event.setField("publicTime", Timestamp.now()); return event; } }