rabbitmq队列卡住的一种情况(webservice接口超时)

一、前言

测试环境发现有一个操作一直没有进行,排查后发现是rabbitmq队列卡住了。

接收的后端代码已经加了完备的try-catch了,但是队列仍然卡住了,并且日志没有报错,就很奇怪。

二、排查过程

1.找到@RabbitListener,先把其中的所有代码删掉,只打印下消息日志,然后发测试,发现这样就可以清空mq队列。

2.恢复测试代码,手写一个controller,入参mq消息json,调用mq处理逻辑,准备打断点测试。

3.查看消息日志,传入手写的controller,打断点测试,发现到一个方法卡住了:

		try {
			JaxWsDynamicClientFactory dcf=JaxWsDynamicClientFactory.newInstance();
			Client client= dcf.createClient("http://128.0.0.1/A/services/BService?wsdl");
			//这个是对面系统的webservice方法名,与入参,<xml>格式的入参报文
			//就是这里卡住了
			Object[] resultObj = client.invoke("createOrenableAccount", new Object[] { accountToXML(userName) });
			String retXML = resultObj[0].toString();
			StringReader read = new StringReader(retXML);
			InputSource source = new InputSource(read);
			SAXBuilder sb = new SAXBuilder();
			Document doc = sb.build(source);
			Element root = doc.getRootElement();
		    LOGGER.info(root.getChildText("code"));// 0  成功
			LOGGER.info(root.getChildText("code") + ", " + root.getChildText("message"));
		} catch (Exception e) {
			LOGGER.error((new StringBuilder("invokeWS Exception:")).append(e).toString(),e);
		}

------------------
	public static String accountToXML(String userName) {
		Document document = null;
		Element et = new Element("account");
		document = new Document(et);
		document = addNode(document, "appname", "AI");
		document = addNode(document, "uid", userName);
		document = addNode(document, "eruid", userName);
		return documentStr(document);
	}
-------------------
	public static String documentStr(Document document) {
		XMLOutputter xop = new XMLOutputter();
		String xmlStr = xop.outputString(document);
		return xmlStr;
	}	

------------------------
pom.xml是这样:
		<!-- Apache CXF -->
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-rs-client</artifactId>
			<version>3.0.0</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-frontend-jaxws</artifactId>
		  <version>3.0.0</version>
		</dependency>

看来是调用其它系统的webservice接口,长时间未响应,接口超时时间>mq超时时间,导致mq消息处理失败,队列就卡住了。

三、解决方法

需要设置webservice请求超时时间,要注意小于mq消息处理超时时间才行。

找到了这个,不过还没有测试:

https://www.yii666.com/blog/169638.html

requestContext.put("com.sun.xml.internal.ws.connection.timeout", 10 * 1000);//建立连接的超时时间为10秒
requestContext.put("com.sun.xml.internal.ws.request.timeout", 15 * 1000);//指定请求的响应超时时间为15秒

//在调用接口方法时,内部会发起一个HTTP请求,发起HTTP请求时会从BindingProvider的getRequestContext()返回结果中获取超时参数,
//分别对应com.sun.xml.internal.ws.connection.timeout和com.sun.xml.internal.ws.request.timeout参数,
//前者是建立连接的超时时间,后者是获取请求响应的超时时间,单位是毫秒。如果没有指定对应的超时时间或者指定的超时时间为0都表示永不超时。

如果不设置,会永不超时,坑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

追逐梦想永不停

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值