use of com.ds.retl.bolt.JmsDistributeBolt in project main by JohnPeng739.
the class JmsManager method createJmsBolt.
/**
* 创建一个JMS数据持久化Bolt,用于存储中间数据
*
* @param supported 支持的JMS类型
* @param config 初始化配置信息
* @return 创建好的数据持久化器Bolt
* @throws JMSException 创建过程中发生的异常
*/
public static BaseRichBolt createJmsBolt(Supported supported, JSONObject config) throws JMSException {
if (config == null) {
throw new NullPointerException("The Jms config is null.");
}
// TODO 根据destinations的不同内容创建JmsBolt或JmsDistributeBolt
JSONArray destinations = config.getJSONArray("destinations");
BaseRichBolt bolt;
if (destinations.size() > 1) {
// 创建JmsDistributeBolt
bolt = new JmsDistributeBolt(destinations);
((JmsDistributeBolt) bolt).setJmsMultiProvider(createProvider(supported, config));
} else {
// 创建JmsBolt
bolt = new JmsBolt();
((JmsBolt) bolt).setJmsProvider(createProvider(supported, config));
((JmsBolt) bolt).setJmsMessageProducer(new JmsMessageProducer() {
@Override
public Message toMessage(Session session, ITuple input) throws JMSException {
// 从元组中读取json字段的值,然后作为一个TextMessage发送
JSONObject managedJson = (JSONObject) input.getValueByField("managedJson");
JSONObject data = (JSONObject) input.getValueByField("data");
if (managedJson == null || data == null) {
if (logger.isWarnEnabled()) {
logger.warn("The ManagedJson or Data is null.");
}
return null;
}
JSONObject json = new JSONObject();
json.put("managedJson", managedJson);
json.put("data", data);
return session.createTextMessage(json.toJSONString());
}
});
}
return bolt;
}
Aggregations