以建立 EncodeTS 為例~
- 在 src/spring-jms-dev.xml 定義 consumer & producer
...
- 建立 consumer & producer
- src/net/sweet/jms/consumer/EncodeTS.java
package net.sweet.jms.consumer; import net.sweet.encode.EncodeObject; import net.sweet.vlog.util.LoggerHelper; import org.apache.activemq.command.ActiveMQMapMessage; import org.apache.log4j.Logger; public class EncodeTS { private static Logger log = Logger.getLogger(EncodeTS.class); public void onMessage(Object message) { ActiveMQMapMessage msg = (ActiveMQMapMessage) message; LoggerHelper loggerHelper = null; EncodeObject obj = null; try { obj = new EncodeObject(msg, log); loggerHelper = new LoggerHelper(log, "/home/logs/jmsc/msg/" + obj.getMsgID() + ".log"); loggerHelper.log("@ EncodeTS consumer ! msgID::::::"+obj.getMsgID()); loggerHelper.log("bye bye !!"); // obj.logInput(); // obj.logOutput(); } catch (Throwable e) { loggerHelper.log(e); } loggerHelper = null; msg = null; obj = null; } }
- src/net/sweet/jms/producer/EncodeTS.java
package net.sweet.jms.producer; import java.util.ArrayList; import net.sweet.VlogJMSConsumer; import net.sweet.encode.EncodeObject; import org.apache.log4j.Logger; public class EncodeTS extends Producer { private static Logger log = Logger.getLogger(EncodeTS.class); public boolean sendMessage(ArrayList
params, EncodeObject obj) { boolean result = false; try { result = super.doSend(params, obj, VlogJMSConsumer.MSG_ENCODE_TS, "encode_ts", template, destination); } catch (InterruptedException e) { obj.getLogHelper().log("FAIL TO SEND EncodeTS! InterruptedException! maybe timeout! exception msg : " + e.getMessage()); log.fatal(e, e); result = false; } catch (Throwable t) { obj.getLogHelper().log("FAIL TO SEND EncodeTS! exception msg : " + t.getMessage()); log.fatal(t, t); result = false; } return result; } } - 增加 src/net/sweet/VlogJMSConsumer.java 內容
- private static EncodeTS encodeTSProducer = null;
- encodeTSProducer = (EncodeTS)ctx.getBean("encodeTSProducer");
- public static final int MSG_ENCODE_TS = 9;
- case MSG_ENCODE_TS: return encodeTSProducer.sendMessage(params, obj);
- 增加 src/net/sweet/jms/producer/Producer.java 內容
... case VlogJMSConsumer.MSG_ENCODE_TS: // 2012-04-03 add by trully case VlogJMSConsumer.MSG_ENCODE_HD_VIDEO: case VlogJMSConsumer.MSG_ENCODE_VIDEO_BY_ON2: case VlogJMSConsumer.MSG_ENCODE_IOS_VIDEO: case VlogJMSConsumer.MSG_ENCODE_IOS_AUDIO: { EncodeObject cloneObj = (EncodeObject)obj.clone(); cloneObj.setMsgID(msgID); msgInst = cloneObj; } break; ...
沒有留言:
張貼留言