简体   繁体   English

java - 通过骆驼处理后无法从 SQS 中删除消息

[英]java - Unable to delete the message from the SQS after it gets processed through the camel

I'm being unable to delete the message from the SQS after it gets processed... I tried several ways explained here on StackOverflow, but none of them worked for me...处理完消息后,我无法从 SQS 中删除消息...我尝试了 StackOverflow 上解释的几种方法,但没有一个对我有用...

Here is the SQS part I'm sending这是我要发送的 SQS 部分

@Override
public void sendTransaction(TransactionModel transactionToSend, String preText) throws EMException {
    try {
        Long companyID = transactionToSend.getCompanyID();
        validateRequest(companyID, transactionToSend.getCostCenterID());
        VendorTransaction vtr = ediManager.convertTransactionToVendorTransaction(transactionToSend);
        EDIOrderRequest ediOrderRequest = ediManager.createEDIOrderRequest(transactionToSend);

        String messageBody = getSQSMessageBody(vtr);
        SendMessageRequest sendMessageRequest = new SendMessageRequest(getQueueName(), messageBody);

        setMessageAttributes(sendMessageRequest, transactionToSend, ediOrderRequest);

        AmazonSQSAsync client = ServerConnector.getServerBean(AWSSQSService.ILocal.class).getSQSClient();
        SendMessageResult result = client.sendMessage(sendMessageRequest);
        if (result == null) {
            throw new EDIException("An error occurred while sending the message.");
        }

        log.info("Transaction: " + transactionToSend.getId() + " for a company: " + companyID + " sent. Message id is: " + result.getMessageId());
    } catch (Exception e) {
        e.printStackTrace();
        log.error(String.format("Error sending transaction: %s", e.getMessage()));
        throw new EMException(-1, String.format("Error sending transaction: %s", e.getMessage()), e);
    }
}

private void setMessageAttributes(SendMessageRequest sendMessageRequest, TransactionModel transactionToSend, EDIOrderRequest ediOrderRequest) {
    addMessageAttributesEntry(sendMessageRequest, "companyId", transactionToSend.getCompanyID());
    addMessageAttributesEntry(sendMessageRequest, "standard", ediConfig.getMapOfParameters().get("EDI_STD"));
    addMessageAttributesEntry(sendMessageRequest, "endpoint", ediConfig.getTargetAddress());
    addMessageAttributesEntry(sendMessageRequest, "prefix", ediConfig.getMapOfParameters().get("FILE_PREFIX"));
    addMessageAttributesEntry(sendMessageRequest, "requestId", ediOrderRequest != null ? ediOrderRequest.getId() : null);
}

Here is the route itself这是路线本身

@Override
public void configure() {

    // on exception deal with EDIOrder stuff
    onException(Exception.class).handled(true).process(failedOrdersProcessor).end();

    String destination = from != null ? from : (sqsQueue);
    destination += "&attributeNames=All&messageAttributeNames=All";
    log.info(destination);
    from(destination)
            .to("direct:ediOrder");
    // order processing
    from("direct:ediOrder")
            .choice()
            .when(body().isInstanceOf(String.class))
            .process(exchange -> {
                //filter out duplicates
                String body = "undefined";
                try {
                    body = exchange.getIn().getBody().toString();
                    VendorTransaction transaction = objectMapper.readValue(body, VendorTransaction.class);
                    if (!IDEMPOTENT_ORDERS_REPOSITORY.containsKey(transaction.getDeduplicatableIdentifier())) {
                        IDEMPOTENT_ORDERS_REPOSITORY.put(transaction.getDeduplicatableIdentifier(), transaction);
                    } else {
                        exchange.getIn().setHeader(Exchange.DUPLICATE_MESSAGE, Boolean.TRUE);
                        if (transaction.getDeduplicatableIdentifier() != null) {
                            exchange.getIn().setHeader(ConfigKey.DEDUPLICATE_IDENTIFIER.getKey(), transaction.getDeduplicatableIdentifier());
                        }
                    }
                } catch (IOException e) {
                    log.error("Unable to convert the body to VendorTransaction, body:\n" + body + "\n" + e.getMessage());
                }
            })
            .end()
            .filter(header(Exchange.DUPLICATE_MESSAGE).isEqualTo(Boolean.TRUE))
            .bean(DuplicateOrderProcessor.class)
            .stop()
            .end()
            .bean(SQSOrderQueueBean.class)
            .choice()
            .when(body().isInstanceOf(EDIOrder.class))
            .recipientList(simple("${body.endpoint}"))
            .log("Uploaded ${body.genericFile.fileName} to ${body.endpointNoPassword}")
            .bean(OrderCleaner.class)
            .endChoice()
            .when(body().isInstanceOf(VendorTransactionContainer.class))
            .log("Send to direct:confirmation")
            .to(RouteConstants.DIRECT_CONFIRMATION)
            .endChoice()
            .end();

The file gets processed and sent to the server, but I'm unable to delete the message after it gets processed.该文件被处理并发送到服务器,但在处理后我无法删除该消息。

Here is the stack trace I get:这是我得到的堆栈跟踪:

WARN  o.a.c.component.aws.sqs.SqsConsumer.log - Error occurred during deleting message. This exception is ignored.. Exchange[ID-AD-MacBook-Pro-local-1353421234311-0-1]. Caused by: [com.amazonaws.services.sqs.model.AmazonSQSException - The request must contain the parameter MessageHandle. (Service: AmazonSQS; Status Code: 400; Error Code: MissingParameter; Request ID: e3252adsaf-1242-2244-a5f6-1b51e2e47e9c)]com.amazonaws.services.sqs.model.AmazonSQSException: The request must contain the parameter MessageHandle. (Service: AmazonSQS; Status Code: 400; Error Code: MissingParameter; Request ID: e3252adsaf-1242-2244-a5f6-1b51e2e47e9c)

If someone thinks that this could be a duplicate question, there are few answers which are similar to this one, here on StackOverflow, but none of them helped me resolve the issue...如果有人认为这可能是一个重复的问题,那么在 StackOverflow 上几乎没有与此类似的答案,但没有一个能帮助我解决问题......

I've fixed this issue by passing the headers to exchange.getOut() message as when we set the body like this我已经通过将标头传递给 exchange.getOut() 消息来解决这个问题,就像我们这样设置正文时一样

exchange.getOut().setBody(body);

we are creating a new instance of a Message, so the headers from exchange.getIn() and everything else from getIn() won't be present in exchange.getOut() message.我们正在创建一个消息的新实例,因此来自 exchange.getIn() 的标头和来自 getIn() 的所有其他内容都不会出现在 exchange.getOut() 消息中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在SQS AWS服务处理之前将消息从队列中出列? - Is it possible to dequeue a message from SQS AWS service even before it gets processed? 成功处理骆驼内部重新传递(交易的骆驼路由)之后,如何防止从MQ Broker重新传递消息 - How to prevent message redelivery from MQ Broker after camel internal redeliveries are successfully processed (transacted camel route) 如何在骆驼 DSL java 中检索 aws sqs 消息属性? - how to retrieve aws sqs message attribute in camel DSL java? AWS Lambda + SQS (Java)。 Lambda 已成功完成工作,但未从 SQS 中删除消息。 是否应再次发送此消息以进行处理? - AWS Lambda + SQS (Java). Lambda successfully was finished work but didn't delete message from SQS. Should this message be sent to process again? Apache Camel:处理后将消息放回原始位置 - Apache Camel: place message back in original location after being processed Apache camel from(file)不会删除已处理的一个 - Apache camel from(file) doesn't delete processed one 使用骆驼的DSL接收SMS消息属性? - receive sqs message attributes using the camel dsl? 删除集群中的已处理文件apache-camel - Delete processed file apache-camel in a cluster 如果收到错误的对象,如何从 SQS 中删除消息? - How to delete a message from SQS in case the wrong object is received? 创建SQS消息后,如何监视它何时被删除? - After creating SQS message, how can I monitor when it gets deleted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM