com.creditease.framework.pojo.ServiceMessage Java Examples
The following examples show how to use
com.creditease.framework.pojo.ServiceMessage.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultBufferManager.java From ns4_frame with Apache License 2.0 | 6 votes |
@Override public synchronized void startUp() { if (!isStarted) { queueNameToReceiveBuffer = new ConcurrentHashMap<String, BlockingQueue<ServiceMessage>>(); queueNameToSendBuffer = new ConcurrentHashMap<String, BlockingQueue<ServiceMessage>>(); Iterator<String> it = queueNameToInQueueInfo.keySet().iterator(); while (it.hasNext()) { String queueName = it.next(); InQueueInfo inQueueInfo = queueNameToInQueueInfo.get(queueName); //构造queue对应的buffer BlockingQueue<ServiceMessage> inBuffer = new LinkedBlockingQueue<ServiceMessage>(inQueueInfo.getBufferSize()); frameLog.debug("# 消息接受缓存初始化 queuename:{} size:{} #", queueName, inQueueInfo.getBufferSize()); queueNameToReceiveBuffer.put(queueName, inBuffer); //TODO 需要sendBuffer也要可以设置buffersize BlockingQueue<ServiceMessage> sendBuffer = new LinkedBlockingQueue<ServiceMessage>(inQueueInfo.getBufferSize()); frameLog.debug("# 消息发送缓存初始化 queuename:{} size:{} #", queueName, inQueueInfo.getBufferSize()); queueNameToSendBuffer.put(queueName, sendBuffer); } isStarted = true; } }
Example #2
Source File: MockMessageTest.java From ns4_frame with Apache License 2.0 | 6 votes |
@Test public void getJsonOut() throws Exception { ServiceMessage message = new MockMessage(); message.setOut(SystemOutKey.SIGN_INFO,"sfsdf"); message.setOut(SystemOutKey.RETURN_CODE, SystemRetInfo.NORMAL); HashMap<Object, Object> objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("a", "b"); objectObjectHashMap.put("c", "f"); objectObjectHashMap.put("e", "z"); message.setOut(TestOutKey.TEST_MAP, objectObjectHashMap); List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); list.add(4); message.setOut(TestOutKey.TEST_LIST, list); message.setOut(TestOutKey.TEST_STRING,"abcdefg"); System.out.println(message.getJsonOut()); }
Example #3
Source File: DefaultBufferManager.java From ns4_frame with Apache License 2.0 | 6 votes |
@Override public ServiceMessage getFromReceiveBuffer(String queueName, boolean isSync) throws InterruptedException, Exception { long startTime = System.currentTimeMillis(); ServiceMessage mqMessage = null; handlerLog.debug("# 获取接收缓存中的消息对象 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); try { if (isSync) { mqMessage = queueNameToReceiveBuffer.get(queueName).take(); } else { mqMessage = queueNameToReceiveBuffer.get(queueName).poll(); } } catch (InterruptedException e) { handlerLog.debug("# 获取接收缓存中对象 失败 线程中断 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); throw e; } NsLog.setMsgId(mqMessage.getHeader().getMessageID()); handlerLog.trace("# messageHeader:{} #", mqMessage.getHeader()); handlerLog.info("# 获取接收缓存中的消息对象 OK queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); return mqMessage; }
Example #4
Source File: DefaultServiceChainBridge.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void doWork(ServiceMessage serviceMessage) throws NSException { //获取当前配置的catalogId long startTime = System.currentTimeMillis(); //如果没有catalogId 报错 if (this.catalogId == null || this.catalogId.trim().length() < 1) { throw new NSException("没有指定本地任务链"); } //得到catalogId后调用chainDispatcher Header header = serviceMessage.getHeader(); Exchanger exchanger = null; try { Map<String,Object> requestScope = new HashMap<String, Object>(); requestScope.put(ChainConstants.DEFAULT_DISPATCHER_KEY, this.catalogId); exchanger = new DefaultExchanger(requestScope); ServiceMessageExchangerAdapter serviceMessageAdapter = new ServiceMessageExchangerAdapter(); serviceMessageAdapter.setServiceMessage(serviceMessage); serviceMessageAdapter.setExchanger(exchanger); exchanger.setExchange(ChainConstants.DEFAULT_SERIVCEMESSAGE_KEY, serviceMessageAdapter); Chain chain = ChainFactory.getDefaultChain(); chain.doChain(exchanger); TransporterLog.logSystemDebug("[中转消息] [成功] [{}] [{}] [{}] [cost:{}ms]",header,exchanger,catalogId,System.currentTimeMillis()-startTime); } catch(NSException exception) { TransporterLog.logSystemError("[中转消息] [失败] [内部执行链停止] [出现异常] [{}] [{}] [{}] [cost:{}ms]",header,exchanger,catalogId,System.currentTimeMillis()-startTime,exception); throw exception; } catch(Exception e) { TransporterLog.logSystemError("[中转消息] [失败] [出现异常] [{}] [{}] [{}] [cost:{}ms]",header,exchanger,catalogId,System.currentTimeMillis()-startTime,e); throw new RuntimeException("出现未知异常"); } }
Example #5
Source File: ActionWorker.java From ns4_frame with Apache License 2.0 | 5 votes |
public static void stop(ServiceMessage serviceMessage, RetInfo retInfo) throws StopException { StopChainException stopException = new StopChainException(retInfo.getMsg()); try { serviceMessage.setOut(SystemOutKey.RETURN_CODE, retInfo); } catch (NSException e) { e.printStackTrace(); } throw stopException; }
Example #6
Source File: MessageOperationUtils.java From ns4_frame with Apache License 2.0 | 5 votes |
/** * @param queueName * @param serviceMessage * @param timeout 单位秒 * @return * @throws IOException */ public static ServiceMessage publish(String queueName, ServiceMessage serviceMessage, int timeout) throws Exception { byte[] bs = ProtoStuffSerializeUtil.serializeForCommon(serviceMessage); Message message = buildMessage(serviceMessage.getHeader(), bs, DeliveryMode.SYNC); if (timeout > 0) { message = mqTemplate.publish(queueName, message, timeout); } else { message = mqTemplate.publish(queueName, message); } DefaultServiceMessage newserviceMessage = (DefaultServiceMessage) MessageConvertUtil.convertToServiceMessage (message); //反射获取servicemessage中的域 String outScopeName = "outScope"; String exchangeScopeName = "exchangeScope"; OutScope outScope = (OutScope) ReflectionUtils.getFieldValue(outScopeName, newserviceMessage); ExchangeScope exchangeScope = (ExchangeScope) ReflectionUtils.getFieldValue(exchangeScopeName, newserviceMessage); ReflectionUtils.setFieldValue(exchangeScopeName, serviceMessage, exchangeScope); ReflectionUtils.setFieldValue(outScopeName, serviceMessage, outScope); return serviceMessage; }
Example #7
Source File: MessageConvertUtil.java From ns4_frame with Apache License 2.0 | 5 votes |
public static ServiceMessage convertToServiceMessage(Message message) throws Exception { byte[] body = message.getBody(); if (body != null) { //先认为是json直接转成的字节,现在转回来 字符集是utf-8 ServiceMessage mqMessage = (ServiceMessage)ProtoStuffSerializeUtil.unSerializeForCommon(body); mqMessage.setHeader(message.getHeader()); return mqMessage; } else { throw new IllegalArgumentException("格式错误,没有消息体"); } }
Example #8
Source File: DefaultBufferManager.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void putInSendBuffer(String queueName, ServiceMessage message) throws Exception { long startTime = System.currentTimeMillis(); handlerLog.debug("# 将消息对象放入发送缓存 queueName:{} sendbuffersize:{} cost:{}ms #", queueName, queueNameToSendBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); ((BlockingQueue<ServiceMessage>) queueNameToSendBuffer.get(queueName)).put(message); handlerLog.trace("# messageHeader:{} #", message.getHeader()); handlerLog.info("# 将消息对象放入发送缓存 OK queueName:{} sendbuffersize:{} cost:{}ms #", queueName, queueNameToSendBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); NsLog.removeMsgId(); }
Example #9
Source File: MessageConvertUtil.java From ns4_frame with Apache License 2.0 | 5 votes |
public static Message convertToMessage(ServiceMessage serviceMessage) throws Exception { Message message = new Message(); message.setHeader(serviceMessage.getHeader()); message.setBody(ProtoStuffSerializeUtil.serializeForCommon(serviceMessage)); return message; }
Example #10
Source File: DefaultBufferManager.java From ns4_frame with Apache License 2.0 | 5 votes |
/** * 这里不需要考虑put的线程安全性,原因如下: * 1.线程不安全的情况下,最危险的情况可能会是放入缓存中消息的顺序,但是在我们这种场景下,消息顺序并不重要 * 2.当前只有一个线程会进行进入队列的缓存存放 * 3.底层是线程安全的 */ @Override public void putInReceiveBuffer(String queueName, ServiceMessage message) throws Exception { long startTime = System.currentTimeMillis(); fetchLog.debug("# 将消息对象放入接收缓存中 queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); queueNameToReceiveBuffer.get(queueName).put(message); fetchLog.trace("# messageHeader:{} #", message.getHeader()); fetchLog.info("# 将消息对象放入接收缓存中 OK queueName:{} receiverbuffersize:{} cost:{}ms #", queueName, queueNameToReceiveBuffer.get(queueName).size(), System.currentTimeMillis() - startTime); NsLog.removeMsgId(); }
Example #11
Source File: FileCheckLActionTcpWorker.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void doWork(ServiceMessage serviceMessage) throws NSException { if (fileCheck.checkFile()) { serviceMessage.setOut(SystemOutKey.XML_OUT_CONTENT, SystemRetInfo.NORMAL); } else { serviceMessage.setOut(SystemOutKey.XML_OUT_CONTENT, SystemRetInfo.CTRL_NOT_FOUND_SEVICE_ERROR); } }
Example #12
Source File: FileCheckLActionWorker.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void doWork(ServiceMessage serviceMessage) throws NSException { if (fileCheck.checkFile()) { serviceMessage.setOut(SystemOutKey.RETURN_CODE, SystemRetInfo.NORMAL); } else { serviceMessage.setOut(SystemOutKey.RETURN_CODE, SystemRetInfo.CTRL_NOT_FOUND_SEVICE_ERROR); } }
Example #13
Source File: NsLogger.java From ns4_gear_idgen with Apache License 2.0 | 5 votes |
private static String makeLog(ServiceMessage serviceMessage) { String fixLog = Constant.EMPTY; try { String retCode = serviceMessage.getExchange(DataExchangeKey.retCode) == null ? Constant.EMPTY : serviceMessage .getExchange(DataExchangeKey.retCode); String retInfo = serviceMessage.getExchange(DataExchangeKey.retInfo) == null ? Constant.EMPTY : serviceMessage .getExchange(DataExchangeKey.retInfo); fixLog = retCode + "|" + retInfo + "|" ; } catch (Exception e) { NsLogger.logger.error("NsLogger.makeLog(); ### 异常", e); } return fixLog; }
Example #14
Source File: StatusLActionTcpWorker.java From ns4_frame with Apache License 2.0 | 5 votes |
@Override public void doWork(ServiceMessage serviceMessage) throws NSException { StringBuilder sb = new StringBuilder(); sb.append(LActionOutKey.queueSize).append(":").append(TcpRPCHandler.getQueueSize()).append(",") .append(LActionOutKey.activeThreadCount).append(":").append(TcpRPCHandler.getActiveThreadCount()); serviceMessage.setOut(SystemOutKey.XML_OUT_CONTENT, sb.toString()); }
Example #15
Source File: NsLogger.java From ns4_gear_idgen with Apache License 2.0 | 4 votes |
public static void error(String serviceId, ServiceMessage serviceMessage, String logMsg) { getLog(serviceId).error(makeLog(serviceMessage) + "-{}", logMsg); }
Example #16
Source File: DefaultBufferManagerProxy.java From ns4_frame with Apache License 2.0 | 4 votes |
@Override public void putInReceiveBuffer(String queueName, ServiceMessage message) { throw new UnsupportedOperationException(); }
Example #17
Source File: ServiceMessageExchangerAdapter.java From ns4_frame with Apache License 2.0 | 4 votes |
public void setServiceMessage(ServiceMessage serviceMessage) { this.serviceMessage = serviceMessage; }
Example #18
Source File: IdGenAction.java From ns4_gear_idgen with Apache License 2.0 | 4 votes |
@Override public void doWork(ServiceMessage serviceMessage) throws NSException { long start = System.currentTimeMillis(); //参数准备 String keyType = serviceMessage.getExchangeByType(DataExchangeKey.keyType, String.class); if (StringUtil.isEmpty(keyType)) { keyType = serviceMessage.getParameter(Constant.PARAM_KEY_TYPE); } String keyName = serviceMessage.getExchangeByType(DataExchangeKey.keyName, String.class); if (StringUtil.isEmpty(keyName)) { keyName = serviceMessage.getParameter(Constant.PARAM_KEY_NAME); } NsLogger.logger.info("IdGenAction dowork... keyType:{},keyName:{}", keyType, keyName); //业务处理 String keyValue = Constant.EMPTY; try { if (!StringUtil.isEmpty(keyType) && !StringUtil.isEmpty(keyName)) { keyValue = counterService.generator(keyType.trim(), keyName.trim()); } NsLogger.logger.info("KeyValue:{} keyType:{} keyName:{}", keyValue, keyType, keyName); } catch (Exception e) { NsLogger.logger.error("response key is empty,error occur"); } //输出结果 serviceMessage.setOut(InterfaceOutKey.result, keyValue); String retCode = InnerMsgEnum.GOT_SUCCESS.getRetCode(); String retInfo = InnerMsgEnum.GOT_SUCCESS.getRetInfo(); if (Constant.EMPTY.equals(keyValue)) { retCode = InnerMsgEnum.GOT_FAIL.getRetCode(); retInfo = InnerMsgEnum.GOT_FAIL.getRetInfo(); } serviceMessage.setOut(SystemOutKey.RETURN_CODE, new GeneralRetInfo(retCode, retInfo)); long end = System.currentTimeMillis(); NsLogger.logger.info("IdGenAction dowork 共耗时{} ms", (end - start)); }
Example #19
Source File: JsonUtil.java From ns4_frame with Apache License 2.0 | 4 votes |
public static <T> T convertToTypeReferenceType(ServiceMessage serviceMessage, ExchangeKey key, TypeReference<T> t) throws Exception { Object o = serviceMessage.getExchangeByType(key, Object.class); return convertToTypeReferenceType(o, t); }
Example #20
Source File: MessageOperationUtils.java From ns4_frame with Apache License 2.0 | 4 votes |
public static void sendMessage(String queueName, ServiceMessage serviceMessage) throws IOException, MQException { byte[] bs = ProtoStuffSerializeUtil.serializeForCommon(serviceMessage); Message message = buildMessage(serviceMessage.getHeader(), bs, DeliveryMode.ASYNC); message.setBody(bs); mqTemplate.send(queueName, message); }
Example #21
Source File: MessageOperationUtils.java From ns4_frame with Apache License 2.0 | 4 votes |
public static ServiceMessage receive(String queueName) throws Exception { Message message = mqTemplate.receive(queueName); return MessageConvertUtil.convertToServiceMessage(message); }
Example #22
Source File: MessageOperationUtils.java From ns4_frame with Apache License 2.0 | 4 votes |
public static void reply(ServiceMessage serviceMessage) throws Exception { Message message = MessageConvertUtil.convertToMessage(serviceMessage); //需要reply 1是同步 mqTemplate.reply(message); }
Example #23
Source File: NsLogger.java From ns4_gear_idgen with Apache License 2.0 | 4 votes |
public static void error(String serviceId, Throwable e, ServiceMessage serviceMessage, String logMsg) { getLog(serviceId).error(e, makeLog(serviceMessage) + "-{}", logMsg); }
Example #24
Source File: NsLogger.java From ns4_gear_idgen with Apache License 2.0 | 4 votes |
public static void info(String serviceId, ServiceMessage serviceMessage, String logMsg) { getLog(serviceId).info(makeLog(serviceMessage) + "-{}", logMsg); }
Example #25
Source File: MonitorEvent.java From ns4_frame with Apache License 2.0 | 4 votes |
public MonitorEvent(Type eventType, ServiceMessage serviceMessage, String queueName, long timeHappend) throws IOException, MQConnectionException, InstantiationException, IllegalAccessException { this(eventType, null, serviceMessage, queueName, timeHappend); }
Example #26
Source File: MonitorEvent.java From ns4_frame with Apache License 2.0 | 4 votes |
public static MonitorEvent createEvent(Type eventType, ServiceMessage serviceMessage, String queueName, long timeHappend) throws IOException, MQConnectionException, IllegalAccessException, InstantiationException { MonitorEvent monitorEvent = new MonitorEvent(eventType, serviceMessage, queueName, timeHappend); return monitorEvent; }
Example #27
Source File: MonitorEvent.java From ns4_frame with Apache License 2.0 | 4 votes |
public static MonitorEvent createEvent(Type eventType, Message message, ServiceMessage serviceMessage, String queueName, long timeHappend) throws IOException, MQConnectionException, InstantiationException, IllegalAccessException { MonitorEvent monitorEvent = new MonitorEvent(eventType, message, serviceMessage, queueName, timeHappend); return monitorEvent; }
Example #28
Source File: NsLogger.java From ns4_gear_idgen with Apache License 2.0 | 4 votes |
public static void debug(String serviceId, ServiceMessage serviceMessage, String logMsg) { getLog(serviceId).debug(makeLog(serviceMessage) + "-{}", logMsg); }
Example #29
Source File: MonitorEvent.java From ns4_frame with Apache License 2.0 | 4 votes |
public ServiceMessage getServiceMessage() { return serviceMessage; }
Example #30
Source File: DefaultBufferManagerProxy.java From ns4_frame with Apache License 2.0 | 4 votes |
@Override public void putInSendBuffer(String queueName, ServiceMessage message) { throw new UnsupportedOperationException(); }