com.dianping.cat.Cat Java Examples
The following examples show how to use
com.dianping.cat.Cat.
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: CatAopService.java From piggymetrics with MIT License | 6 votes |
@Around("@annotation(CatAnnotation)") public Object aroundMethod(ProceedingJoinPoint pjp) { MethodSignature joinPointObject = (MethodSignature) pjp.getSignature(); Method method = joinPointObject.getMethod(); Transaction t = Cat.newTransaction("method", method.getName()); try { Object obj = pjp.proceed(); t.setSuccessStatus(); return obj; } catch (Throwable e) { t.setStatus(e); Cat.logError(e); throw new RuntimeException("Exception thrown by CAT aop", e); } finally { t.complete(); } }
Example #2
Source File: AcemFinancialUIApplication.java From cat_lab with MIT License | 6 votes |
@RequestMapping("/readtimeout") public String timeout() throws InterruptedException { Transaction t = Cat.newTransaction(CatConstants.TYPE_URL, "timeout"); try { Thread.sleep(300); log.info("Hello from service1. Calling service2 - should end up with read timeout"); String response = restTemplate.getForObject("http://" + serviceAddress + "/readtimeout", String.class); log.info("Got response from service2 [{}]", response); return response; } catch (Exception e) { Cat.getProducer().logError(e); t.setStatus(e); throw e; } finally { t.complete(); } }
Example #3
Source File: CatAop.java From javabase with Apache License 2.0 | 6 votes |
private Object aroundTransaction(String type, String name, ProceedingJoinPoint joinPoint) throws Throwable { Object result = null; Transaction transaction = null; //不让cat异常导致业务异常 try { transaction = Cat.getProducer().newTransaction(type, name); } catch (Exception e) { log.error("Cat.getProducer().newTransaction Error", e); } try { log.info("大众点评cat拦截:type="+type+";name="+name); result = joinPoint.proceed(); if (transaction != null) transaction.setStatus(Transaction.SUCCESS); } catch (Throwable throwable) { if (transaction != null) transaction.setStatus(throwable); log.error("aroundTransaction exception", throwable); throw throwable; } finally { if (transaction != null) transaction.complete(); } return result; }
Example #4
Source File: SendMessageCommandProcessor.java From hermes with Apache License 2.0 | 6 votes |
private boolean isRateLimitExceeded(String topic, int partition, int msgCount, int bytes) { RateLimiter qpsRateLimiter = m_config.getPartitionProduceQPSRateLimiter(topic, partition); RateLimiter bytesRateLimiter = m_config.getPartitionProduceBytesRateLimiter(topic, partition); if (qpsRateLimiter.tryAcquire(msgCount)) { if (bytesRateLimiter.tryAcquire(bytes)) { return false; } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_BYTES_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_QPS_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } return true; }
Example #5
Source File: SendMessageCommandProcessorV3.java From hermes with Apache License 2.0 | 6 votes |
private boolean isRateLimitExceeded(String topic, int partition, int msgCount, int bytes) { RateLimiter qpsRateLimiter = m_config.getPartitionProduceQPSRateLimiter(topic, partition); RateLimiter bytesRateLimiter = m_config.getPartitionProduceBytesRateLimiter(topic, partition); if (qpsRateLimiter.tryAcquire(msgCount)) { if (bytesRateLimiter.tryAcquire(bytes)) { return false; } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_BYTES_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_QPS_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } return true; }
Example #6
Source File: SendMessageCommandProcessorV5.java From hermes with Apache License 2.0 | 6 votes |
private boolean isRateLimitExceeded(String topic, int partition, int msgCount, int bytes) { RateLimiter qpsRateLimiter = m_config.getPartitionProduceQPSRateLimiter(topic, partition); RateLimiter bytesRateLimiter = m_config.getPartitionProduceBytesRateLimiter(topic, partition); if (qpsRateLimiter.tryAcquire(msgCount)) { if (bytesRateLimiter.tryAcquire(bytes)) { return false; } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_BYTES_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } } else { Cat.logEvent(CatConstants.TYPE_MESSAGE_BROKER_QPS_RATE_LIMIT_EXCEED, topic + "-" + partition, Event.SUCCESS, "msgCount=" + msgCount + "&bytes=" + bytes); } return true; }
Example #7
Source File: CatInvokeTrace.java From octo-rpc with Apache License 2.0 | 6 votes |
@Override protected void serverSendInFilter(TraceParam traceParam, RpcInvocation invocation) { Transaction transaction = (Transaction) traceParam.getAttachment(TRANSACTION); if (transaction == null) { logger.warn("ServerSide: Request {} won't do cat report, cause no start transaction info.", traceParam.getSpanName()); return; } try { serverLogEvent(traceParam, invocation); transaction.addData(TRACE_ID, traceParam.getTraceId()); if (traceParam.getThrowable() == null) { transaction.setStatus(Transaction.SUCCESS); } else { Cat.logErrorWithCategory(DORADO_SERVICE + "." + traceParam.getRemoteAppkey(), traceParam.getThrowable()); transaction.setStatus(traceParam.getThrowable()); } } catch (Exception e) { Cat.logErrorWithCategory(DORADO_SERVICE + "." + traceParam.getRemoteAppkey(), e); transaction.setStatus(e); } finally { transaction.complete(); } }
Example #8
Source File: PageCacheBuilder.java From hermes with Apache License 2.0 | 6 votes |
private void loadPage(final Page<T> page) { if (page != null && page.startLoading()) { m_pageLoaderThreadPool.submit(new Runnable() { @Override public void run() { try { m_pageLoader.loadPage(page); } catch (Exception e) { Cat.logError("Exception occurred while loading page", e); log.error("Exception occurred while loading page", e); } finally { page.endLoading(); } } }); } }
Example #9
Source File: DefaultMessageQueueFlusher.java From hermes with Apache License 2.0 | 6 votes |
private long purgeExpiredMsgs() { long maxPurgedSelectorOffset = Long.MIN_VALUE; long now = System.currentTimeMillis(); long purgedCount = 0; while (!m_pendingMessages.isEmpty()) { if (m_pendingMessages.peek().getExpireTime() < now) { long purgedSelectorOfset = purgeExpiredMsg(); maxPurgedSelectorOffset = Math.max(maxPurgedSelectorOffset, purgedSelectorOfset); purgedCount++; } else { break; } } if (purgedCount > 0) { Cat.logEvent(CatConstants.TYPE_MESSAGE_PRODUCE_QUEUE_EXPIRED, m_topic, Event.SUCCESS, "*count=" + purgedCount); } return maxPurgedSelectorOffset; }
Example #10
Source File: CatAppender4Log4j2.java From x-pipe with Apache License 2.0 | 6 votes |
private void logTrace(LogEvent event) { String type = "Log4j"; String name = event.getLevel().toString(); Object message = event.getMessage(); String data; if (message instanceof Throwable) { data = buildExceptionStack((Throwable) message); } else { data = event.getMessage().toString(); } Throwable info = event.getThrown(); if (info != null) { String extra = ExceptionUtils.extractExtraMessage(info); if(extra != null){ data += "\n" + extra; } data += '\n' + buildExceptionStack(info); } Cat.logTrace(type, name, Trace.SUCCESS, data); }
Example #11
Source File: CatLog4j2ErrorAppender.java From hermes with Apache License 2.0 | 6 votes |
private void logError(LogEvent event) { try { Throwable throwable = event.getThrown(); if (throwable != null) { Object message = event.getMessage(); if (message != null) { Cat.logError(String.valueOf(message), throwable); } else { Cat.logError(throwable); } } } catch (Throwable e) { // ignore } }
Example #12
Source File: CatTransactionMonitor.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public <V> V logTransactionSwallowException(String type, String name, Callable<V> task) { Transaction transaction = Cat.newTransaction(type, name); try{ V result = task.call(); transaction.setStatus(Transaction.SUCCESS); return result; }catch(Throwable th){ transaction.setStatus(th); logger.error("[logTransaction]" + type + "," + name + "," + task, th); }finally{ transaction.complete(); } return null; }
Example #13
Source File: CatController.java From javabase with Apache License 2.0 | 6 votes |
/** * Cat.newTransaction 与Cat.getProducer().newTransaction 区别在于 一个是重新生成一个transation 和获取当前线程绑定的transaction“ * * @return * @throws Exception */ @RequestMapping(value = "/cycletransation", method = RequestMethod.GET) public String newtransation() throws Exception { Transaction t = Cat.getProducer().newTransaction("TransactionTest", "Cat.getProducer()"); Cat.getProducer().logEvent("eventType1", "1", Message.SUCCESS, ""); Cat.getProducer().logEvent("eventType1", "2", Message.SUCCESS, ""); Transaction t2 = Cat.getProducer().newTransaction("TransactionTest-1", "child transaction 1"); Cat.getProducer().logEvent("eventType2-1", "2-1", Message.SUCCESS, ""); Cat.getProducer().logEvent("eventType2-2", "2-2", Message.SUCCESS, ""); t2.addData("tChild transaction-1"); t2.setStatus(Message.SUCCESS); t2.complete(); Transaction t3 = Cat.getProducer().newTransaction("TransactionTest-2", "child transaction 2"); Cat.getProducer().logEvent("eventType3-1", "3-1", Message.SUCCESS, ""); Cat.getProducer().logEvent("eventType3-2", "3-2", Message.SUCCESS, ""); t3.addData("Child transaction-2"); t3.setStatus(Message.SUCCESS); // 休眠3s 验证时间 Thread.sleep(4000); t3.complete(); t.addData(" Parent transaction"); t.setStatus(Message.SUCCESS); t.complete(); return ""; }
Example #14
Source File: DefaultPullConsumerHolder.java From hermes with Apache License 2.0 | 6 votes |
@Override public PulledBatch<T> poll(int maxMessageCount, int timeout) { long startTime = System.currentTimeMillis(); Transaction t = Cat.newTransaction(CatConstants.TYPE_MESSAGE_CONSUME_POLL_TRIED, m_topic + ":" + m_group); try { PulledBatch<T> batch = retrive(maxMessageCount, timeout, RetrivePolicy.FAVOUR_FAST_RETURN); if (batch.getMessages() != null && !batch.getMessages().isEmpty()) { CatUtil.logElapse(CatConstants.TYPE_MESSAGE_CONSUME_POLL_ELAPSE, m_topic + ":" + m_group, startTime, batch .getMessages().size(), null, Transaction.SUCCESS); } return batch; } finally { t.setStatus(Transaction.SUCCESS); t.complete(); } }
Example #15
Source File: BaseMessageListener.java From hermes with Apache License 2.0 | 6 votes |
private void setOnMessageStartTime(ConsumerMessage<T> msg) { if (msg instanceof BaseConsumerMessageAware) { BaseConsumerMessage<?> baseMsg = ((BaseConsumerMessageAware<?>) msg).getBaseConsumerMessage(); long now = System.currentTimeMillis(); baseMsg.setOnMessageStartTimeMills(now); Transaction latencyT = null; if (!msg.isResend()) { latencyT = Cat.newTransaction( // CatConstants.TYPE_MESSAGE_CONSUME_LATENCY, msg.getTopic() + ":" + m_groupId); } else { latencyT = Cat.newTransaction( // CatConstants.TYPE_MESSAGE_CONSUME_RESEND_LATENCY, msg.getTopic() + ":" + m_groupId); } long delta = System.currentTimeMillis() - baseMsg.getBornTime(); if (latencyT instanceof DefaultTransaction) { ((DefaultTransaction) latencyT).setDurationStart(System.nanoTime() - delta * 1000000L); } latencyT.addData("key", msg.getRefKey()); latencyT.setStatus(Transaction.SUCCESS); latencyT.complete(); } }
Example #16
Source File: CatAppender4Log4j2.java From x-pipe with Apache License 2.0 | 6 votes |
@Override public void append(LogEvent event) { MessageManager messageManager = Cat.getManager(); boolean isTraceMode = false; if(messageManager != null){ isTraceMode = messageManager.isTraceMode(); } Level level = event.getLevel(); if (level.isMoreSpecificThan(Level.ERROR)) { logError(event); } else if (isTraceMode) { logTrace(event); } }
Example #17
Source File: CatAppender4Log4j2.java From x-pipe with Apache License 2.0 | 6 votes |
private void logError(LogEvent event) { Throwable info = event.getThrown(); if (info != null) { Throwable exception = info; Object message = event.getMessage(); String extra = ExceptionUtils.extractExtraMessage(info); String logMessage = StringUtil.join(",", message, extra); if (!StringUtil.isEmpty(logMessage)) { Cat.logError(logMessage, exception); } else { Cat.logError(exception); } } }
Example #18
Source File: CatFilter.java From Zebra with Apache License 2.0 | 6 votes |
@Override public void initShardDataSource(com.dianping.zebra.shard.jdbc.ShardDataSource source, JdbcFilter chain) { String ruleName = source.getRuleName(); if (StringUtils.isBlank(ruleName)) { ruleName = "localMode"; } Transaction transaction = Cat.newTransaction(CAT_TYPE, "ShardDataSource.Init-" + ruleName); try { chain.initShardDataSource(source, chain); transaction.setStatus(Message.SUCCESS); } catch (RuntimeException e) { Cat.logError(e); transaction.setStatus(e); throw e; } finally { transaction.complete(); } }
Example #19
Source File: CatFilter.java From Zebra with Apache License 2.0 | 6 votes |
@Override public int executeShardUpdate(ShardStatement source, String sql, int autoGeneratedKeys, int[] columnIndexes, String[] columnNames, JdbcFilter chain) throws SQLException { SqlAliasManager.setSqlAlias(sql); Transaction t = Cat.newTransaction(SHARD_CAT_TYPE, SqlAliasManager.getSqlAlias()); int result; try { result = chain.executeShardUpdate(source, sql, autoGeneratedKeys, columnIndexes, columnNames, chain); t.setStatus(Message.SUCCESS); } catch (Throwable exp) { Cat.logError(exp); t.setStatus(exp); throw new SQLException(exp); } finally { t.complete(); } return result; }
Example #20
Source File: CatFilter.java From Zebra with Apache License 2.0 | 6 votes |
@Override public ResultSet executeShardQuery(ShardStatement source, String sql, JdbcFilter chain) throws SQLException { SqlAliasManager.setSqlAlias(sql); Transaction t = Cat.newTransaction(SHARD_CAT_TYPE, SqlAliasManager.getSqlAlias()); ResultSet result = null; try { result = chain.executeShardQuery(source, sql, chain); t.setStatus(Message.SUCCESS); } catch (Throwable exp) { Cat.logError(exp); t.setStatus(exp); throw new SQLException(exp); } finally { t.complete(); } return result; }
Example #21
Source File: AsyncZuulServlet.java From s2g-zuul with MIT License | 6 votes |
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { Transaction tran = Cat.getProducer().newTransaction("AsyncZuulServlet", req.getRequestURL().toString()); req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true); AsyncContext asyncContext = req.startAsync(); asyncContext.setTimeout(asyncTimeout.get()); asyncContext.addListener(new AsyncZuulListener()); try { Context ctx = new CatContext(); Cat.logRemoteCallClient(ctx); poolExecutorRef.get().submit(new ZuulCallable(ctx,asyncContext, zuulRunner,req)); tran.setStatus(Transaction.SUCCESS); } catch (RuntimeException e) { Cat.logError(e); tran.setStatus(e); rejectedRequests.incrementAndGet(); throw e; }finally{ tran.complete(); } }
Example #22
Source File: ConsumerLeaseHolder.java From hermes with Apache License 2.0 | 6 votes |
private long loadNewLeasesAssignedByOtherMetaservers(long lastRunTime) throws DalException { Transaction transaction = Cat.newTransaction(CatConstants.TYPE_LEASE_DIRTY_LOAD, "Consumer"); int count = 0; long maxLodedTime = -1L; try { List<ConsumerLease> changes = m_leasesDao.listLatestChanges(new Date(lastRunTime), Networks.forIp() .getLocalHostAddress(), ConsumerLeaseEntity.READSET_FULL); if (changes != null && !changes.isEmpty()) { count = changes.size(); maxLodedTime = loadExistingLeases(changes); } transaction.setStatus(Transaction.SUCCESS); return maxLodedTime; } catch (Exception e) { transaction.setStatus(e); throw e; } finally { transaction.addData("count", count); transaction.complete(); } }
Example #23
Source File: CatAopService.java From piggymetrics with MIT License | 6 votes |
@Around("@annotation(CatAnnotation)") public Object aroundMethod(ProceedingJoinPoint pjp) { MethodSignature joinPointObject = (MethodSignature) pjp.getSignature(); Method method = joinPointObject.getMethod(); Transaction t = Cat.newTransaction("method", method.getName()); try { Object obj = pjp.proceed(); t.setSuccessStatus(); return obj; } catch (Throwable e) { t.setStatus(e); Cat.logError(e); throw new RuntimeException("Exception thrown by CAT aop", e); } finally { t.complete(); } }
Example #24
Source File: ZuulRequestCommandForSemaphoreIsolation.java From s2g-zuul with MIT License | 6 votes |
@Override protected HttpResponse run() throws Exception { Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, httpUriRequest.getURI().toString()); try { HttpResponse response = forward(); t.setStatus(Transaction.SUCCESS); return response; } catch (IOException e) { t.setStatus(e); Cat.logError(e); throw e; } finally { t.complete(); } }
Example #25
Source File: XpipeDalTransactionManager.java From x-pipe with Apache License 2.0 | 5 votes |
public boolean isInTransaction() { try { if (m_connection != null && m_connection.isClosed()) { return false; } } catch (SQLException e) { Cat.logError(e); } return m_inTransaction; }
Example #26
Source File: CatRestInterceptor.java From piggymetrics with MIT License | 5 votes |
@Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString()); try { HttpHeaders headers = request.getHeaders(); // 保存和传递CAT调用链上下文 Context ctx = new CatContext(); Cat.logRemoteCallClient(ctx); headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT)); headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT)); headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD)); // 保证请求继续被执行 ClientHttpResponse response = execution.execute(request, body); t.setStatus(Transaction.SUCCESS); return response; } catch (Exception e) { Cat.getProducer().logError(e); t.setStatus(e); throw e; } finally { t.complete(); } }
Example #27
Source File: ConfigSubscriber.java From AsuraFramework with Apache License 2.0 | 5 votes |
/** * 初始化zk连接 * * @author zhangshaobin * @created 2013-6-26 上午10:21:34 */ private void init() { applicationName = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.CONFIG_APPLICATION_NAME_KEY, null).get(); String zkConfigEnsemble = DynamicPropertyFactory.getInstance().getStringProperty(CommonConstant.ZK_ENSEMABLE_KEY, null).get(); Integer zkConfigSessionTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_SESSION_TIMEOUT_KEY, 15000).get(); Integer zkConfigConnTimeout = DynamicPropertyFactory.getInstance().getIntProperty(CommonConstant.ZK_CONN_TIMEOUT_KEY, 5000).get(); Transaction tran = Cat.newTransaction("Asura Configuration init", applicationName + "_" + zkConfigEnsemble); try { if (Check.NuNStr(zkConfigEnsemble)) { logger.warn("ZooKeeper configuration running in file mode, zk is not enabled since not configured"); Cat.logError("zk is not enabled since not configured", new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started.")); return; } client = createAndStartZKClient(zkConfigEnsemble, zkConfigSessionTimeout, zkConfigConnTimeout); if (client.getState() != CuratorFrameworkState.STARTED) { throw new RuntimeException("ZooKeeper located at " + zkConfigEnsemble + " is not started."); } tran.setStatus(Transaction.SUCCESS); } catch (Exception e) { logger.error("连接配置中心服务器超时,时间5000毫秒。", e); Cat.logError("asura configuration init exception", e); tran.setStatus(e); System.exit(1); } finally { tran.complete(); } logger.info(new SimpleDateFormat("[yyyy-MM-dd HH:mm:ss] ").format(new Date()) + applicationName + " connected to cofnig server(" + zkConfigEnsemble + ")."); logger.info(applicationName + " connected to cofnig server(" + zkConfigEnsemble + ")."); }
Example #28
Source File: ClusterStateHolder.java From hermes with Apache License 2.0 | 5 votes |
public void becomeFollower() { m_roleLock.writeLock().lock(); try { log.info("Become Follower!!!"); Cat.logEvent(CatConstants.TYPE_ROLE_CHANGED, "Follower"); m_role = Role.FOLLOWER; long newVersion = m_guard.upgradeVersion(); startLeaderLatch(); m_eventBus.pubEvent(new Event(EventType.FOLLOWER_INIT, newVersion, null)); } finally { m_roleLock.writeLock().unlock(); } }
Example #29
Source File: MyBatisCatPlugin.java From javabase with Apache License 2.0 | 5 votes |
@Override public Object intercept(Invocation invocation) throws Throwable { Object result = null; Transaction transaction = null; MappedStatement mappedStatement = (MappedStatement)invocation.getArgs()[0]; Object objects = (Object)invocation.getArgs()[1]; BoundSql boundSql = mappedStatement.getBoundSql(objects); // 得到 类名-方法 String[] strArr = mappedStatement.getId().split("\\."); String class_method = strArr[strArr.length - 2] + "." + strArr[strArr.length - 1]; String sql = getSql(mappedStatement.getConfiguration(), boundSql); try { transaction = Cat.getProducer().newTransaction("SQL", class_method); result = invocation.proceed(); Cat.getProducer().logEvent("SQL.Method", mappedStatement.getSqlCommandType().name(), Message.SUCCESS, ""); // Cat.getProducer().logEvent("SQL.Database","" ,Message.SUCCESS,""); Cat.getProducer().logEvent("SQL.Statement", sql.substring(0, sql.indexOf(" ")), Message.SUCCESS, sql); transaction.setStatus(Message.SUCCESS); } catch (InvocationTargetException | IllegalAccessException e) { transaction.setStatus( ((InvocationTargetException)e).getTargetException().toString()); log.error( ((InvocationTargetException)e).getTargetException().toString()); Cat.getProducer().logError( ((InvocationTargetException)e).getTargetException().toString(), e); throw e; } finally { // transaction.addData(boundSql.getSql().trim().replaceAll("\\n","")); transaction.complete(); } return result; }
Example #30
Source File: RabbitMqSendClient.java From AsuraFramework with Apache License 2.0 | 5 votes |
private void sendQueue(QueueName queueName, RabbitMessage rm) throws Exception { if (rm == null || queueName == null) { return; } initQueueChannel(); String _queueName = queueName.getNameByEnvironment(environment); Transaction trans = Cat.newTransaction("RabbitMQ Message", "PUBLISH-QUEUE-" + _queueName); Cat.logEvent("mq send queue", _queueName, Event.SUCCESS,rm.toJsonStr()); try { queueChannel.queueDeclare(_queueName, true, false, false, null); queueChannel.basicPublish("", _queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, rm.toJsonStr().getBytes("UTF-8")); if (LOGGER.isInfoEnabled()) { LOGGER.info("SEND SUCCESS:[queue:{},message:{}]", _queueName, rm.toJsonStr()); } Cat.logMetricForCount("PUBLISH-QUEUE-" + _queueName); // 统计请求次数, 可以查看对应队列中放入了多少信息 trans.setStatus(Transaction.SUCCESS); } catch (Exception e) { if (LOGGER.isErrorEnabled()) { LOGGER.error("SEND ERROR:[queue:{},message:{},exception:{}]", _queueName, rm.toJsonStr(), e); } String err = queueName + " rabbitmq发送消息异常"; Cat.logError(err, e); trans.setStatus(e); throw new AsuraRabbitMqException(err, e); } finally { trans.complete(); } }