从服务总线拉消息时例外



我想从服务总线中摘下一条消息。消息不过是XML。我想使用PEEK_LOCK选项来实现目标。

目前,队列中没有消息。我的代码每30秒通过时间表。如果队列中有任何消息,它将拉动消息否则会打印不再是消息

ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
opts.setReceiveMode(ReceiveMode.PEEK_LOCK);
service.getQueue(queueName).getValue().setMaxSizeInMegabytes((long) 1);
BrokeredMessage message;
message = service.receiveQueueMessage(queueName).getValue();
StreamSource source = null;
ResponseEntity<String> response = null;
LOG.debug("Message: " + message);
// LOG.debug("message.getMessageId(): " + message.getMessageId());
// try {
if (message != null) {
    source = new StreamSource(message.getBody());
    StringWriter outWriter = new StringWriter();
    StreamResult result = new StreamResult(outWriter);
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Transformer transformer = tFactory.newTransformer();
    transformer.transform(source, result);
    StringBuffer sb = outWriter.getBuffer();
    String finalstring = sb.toString();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource src = new InputSource();
    src.setCharacterStream(new StringReader(finalstring));
    Document doc = builder.parse(src);
    String ecnNo = doc.getElementsByTagName(xmlECNNoTag).item(0).getTextContent();
    LOG.info(ecnNo + " Is pulled from queue "); 
    if (LOG.isDebugEnabled()) {
        LOG.info("XML Content: " + finalstring);
    }
}
service.deleteMessage(message);

如果我删除peek_lock代码,我的代码正常工作。使用peek_lock,我会得到此错误:

javax.xml.transform.transformerexception: org.xml.sax.saxparseexception;亚麻数:1;柱子:50;白色的 在publicId和SystemID之间需要空间。在 com.sun.org.apache.xalan.internal.xsltc.trax.trax.transformerimpl.transform(Transformerimpl.java:749) 〜[na:1.8.0_66] at com.sun.org.apache.xalan.internal.xsltc.trax.trax.transformerimpl.transform(trransformerimpl.java:351) 〜[na:1.8.0_66] at com.jci.subscriber.service.plmsubscribermsserviceimpl.azuremessagesageSubscriber(plmsubsubscribermsserviceimpl.java:160) 〜[class/:na]在 com.jci.subscriber.plmsubscribermsapplication.getxml(plmsubsubscribermsapplication.java:118) [class/:na]在sun.reflect.generatedmethodaccessor101.invoke(未知) 来源)〜[na:na] at sun.reflect.delegatingmethodaccessorimpl.invoke(授权methodaccessorimpl.java:43) 〜[na:1.8.0_66]在java.lang.reflect.method.invoke(method.java:497) 〜[na:1.8.0_66] at org.springframework.scheduling.support.scheduledmethodrunnable.run(steeduledmethodrunnable.java:65) [Spring-Context-4.2.6.Release.Jar:4.2.6.Release] at org.springframework.scheduling.support.delegatingerrorhandlingrunnable.run(delegatingerronhandlingrunnable.java:54) [Spring-Context-4.2.6.Release.Jar:4.2.6.Release] at java.util.concurrent.executors $ runnableDapter.call(executors.java:511) [NA:1.8.0_66]在 java.util.concurrent.futuretask.runandreset(futuretask.java:308) [NA:1.8.0_66]在 java.util.concurrent.scheduledthreadpoolexecutor $ scheduledfuturetask.access $ 301(scheduledthreadpoolexecutor.java:180) [NA:1.8.0_66]在 java.util.concurrent.scheduledthreadpoolexecutor $ scheduledfuturetask.run(scheduledthreadpoolexecutor.java:294) [NA:1.8.0_66]在 java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) [NA:1.8.0_66]在 java.util.concurrent.threadpoolexecutor $ worker.run(threadpoolexecutor.java:617) [NA:1.8.0_66]在Java.lang.thread.run(thread.java:745)[NA:1.8.0_66] 引起:org.xml.sax.saxparseexception:需要白色空间 在puculiD和SystemId之间。在 com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(AbstractSaxparser.java:1239) 〜[na:1.8.0_66] at com.sun.org.apache.xalan.internal.xsltc.trax.trax.transformerimpl.transformidentity(trransformerimpl.java:641) 〜[na:1.8.0_66] at com.sun.org.apache.xalan.internal.xsltc.trax.trax.transformerimpl.transform(trransformerimpl.java:737) 〜[NA:1.8.0_66] ... 15省略的常见帧

根据例外,根据我的经验,我认为问题是由通过DocumentBuilderpeek_lock模式从服务总线验证消息的远程DTD模式引起的。

有一些解决方法如下。

  1. 尝试使用方法 [DocumentBuilderFactory.setValidating(boolean validating)] 1来禁用以下消息的验证。

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(false);
    DocumentBuilder builder = factory.newDocumentBuilder();
    
  2. 尝试通过方法DocumentBuilder.setEntityResolver(EntityResolver er)DocumentBuilder设置自定义EntityResolver对象,请参阅SO线程make make documentBuilder.parse ivailore dtd引用。

builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { if (systemId.contains("foo.dtd")) { return new InputSource(new StringReader("")); } else { return null; } } });

  1. 尝试使用dom4j等第三方库来解析消息。

希望它有帮助。任何问题,请随时让我知道。

相关内容

  • 没有找到相关文章

最新更新