0

我正在使用以下服务器端重新交付配置

 <plugins>
    <redeliveryPlugin fallbackToDeadLetter="true" sendToDlqIfMaxRetriesExceeded="true">
        <redeliveryPolicyMap>
            <redeliveryPolicyMap>
                <redeliveryPolicyEntries>
                    <redeliveryPolicy 
                        queue = "com.api.RequestQueue.v1"
                        maximumRedeliveries="20"                        
                        initialRedeliveryDelay="60000" 
                        redeliveryDelay="60000" />

                    <redeliveryPolicy 
                        queue = "com.api.RequestQueue.v2"
                        maximumRedeliveries="10"                        
                        initialRedeliveryDelay="30000" 
                        redeliveryDelay="30000" />
                    <redeliveryPolicy 
                        queue = "com.api.ResponseQueue.v1"
                        maximumRedeliveries="3"                         
                        initialRedeliveryDelay="34000" 
                        redeliveryDelay="34000" />                          
                </redeliveryPolicyEntries>
            </redeliveryPolicyMap>
        </redeliveryPolicyMap>
    </redeliveryPlugin>
</plugins>

如何设置自定义端点以在重试后和发送到 DLQ 之前处理失败的消息?我确实参考了以下链接,但找不到有关服务器端或 redeliveryPlugin 配置的任何内容

1.死信通道

2.记录骆驼异常并发送到死信通道

4

2 回答 2

2

如果您使用的是 blueprint 或 spring,那么它可以很容易地完成:

<!-- Redelivery Policy -->
<bean class="org.apache.camel.processor.RedeliveryPolicy" id="redeliveryPolicyConfig">
    <property name="5" />
    <property name="redeliveryDelay" value="5000" />
    <property name="logRetryAttempted" value="true" />
</bean>

<!-- Error Handler -->
<bean class="org.apache.camel.builder.DeadLetterChannelBuilder" id="errorHandler">
    <property name="deadLetterUri" value="direct:error" />
    <property name="useOriginalMessage" value="true" />
    <property name="redeliveryPolicy" ref="redeliveryPolicyConfig" />
</bean>

然后在“deadLetterUri”属性中添加错误处理程序指向的路由,如下所示:

<!-- Perform custom logic and send to DLQ -->
<route id="myDLQ-route">
    <from uri="direct:error" />
    <!-- Maybe some logic here, logging perhaps? -->
    <to uri="activemq:queue:myDLQ" />
</route>
于 2017-02-15T15:28:24.127 回答
0

我用的是spring,但是重投的配置是在单独的broker容器中,目前无法更改。

但是以下配置有效。

路线:

     public class MyMessageRoute extends RouteBuilder {
       public void configure() throws Exception {
           onException(Exception.class)
            .handled(true)
            .bean(PreDLQLogWriter.class) ;

           from(fromQueueName).id("RouteId")
            .transacted()
            //process message 

            ;
       }}

public class PreDLQLogWriter {
private static final org.slf4j.Logger LOG = 
                 org.slf4j.LoggerFactory.getLogger( PreDLQLogWriter.class ); 

int configuredDeliveryCount = maximumRedeliveries+1;
public void logMessageDetails(Exchange exchange) throws Exception {

  int actualDeliveryCount = exchange.getIn().getHeader("JMSXDeliveryCount") 
                   != null ? exchange.getIn().getHeader("JMSXDeliveryCount", 
                    Integer.class) : 0 ;
  if(actualDeliveryCount = configuredDeliveryCount) {
             LOG.info(" Pre-DLQ Log: Log the message with message id ");
   }}
于 2017-05-30T10:38:51.747 回答