Mule ESB,ActiveMQ和DLQ

apache-activemq-logo
在本文中,我将展示一个简单的Mule ESB流程,以了解实际中使用的Active MQ 的DLQ功能 。
我假设您有一个正在运行的Apache ActiveMQ实例(如果没有,则可以在此处下载一个版本)。 在此示例中,我使用了Mule ESB 3.4.2和ActiveMQ 5.9.0。 我们可以基于以下pom文件创建一个简单的Mule项目:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>net.pascalalma.demo</groupId><artifactId>activemq-test-flow</artifactId><packaging>mule</packaging><name>${project.artifactId}</name><version>1.0.0-SNAPSHOT</version><properties><mule.version>3.4.2</mule.version><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><jdk.version>1.7</jdk.version><junit.version>4.9</junit.version><activemq.version>5.9.0</activemq.version></properties><dependencies><!-- Mule Dependencies --><dependency><groupId>org.mule</groupId><artifactId>mule-core</artifactId><version>${mule.version}</version></dependency><!-- Mule Transports --><dependency><groupId>org.mule.transports</groupId><artifactId>mule-transport-jms</artifactId><version>${mule.version}</version></dependency><dependency><groupId>org.mule.transports</groupId><artifactId>mule-transport-vm</artifactId><version>${mule.version}</version></dependency><!-- Mule Modules --><dependency><groupId>org.mule.modules</groupId><artifactId>mule-module-client</artifactId><version>${mule.version}</version></dependency><dependency><groupId>org.mule.modules</groupId><artifactId>mule-module-scripting</artifactId><version>${mule.version}</version></dependency><!-- for testing --><dependency><groupId>org.mule.tests</groupId><artifactId>mule-tests-functional</artifactId><version>${mule.version}</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version></dependency><dependency><groupId>org.apache.activemq</groupId><artifactId>activemq-client</artifactId><version>${activemq.version}</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>2.3.2</version><configuration><source>${jdk.version}</source><target>${jdk.version}</target><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-resources-plugin</artifactId><version>2.5</version><configuration><encoding>${project.build.sourceEncoding}</encoding></configuration></plugin><plugin><groupId>org.mule.tools</groupId><artifactId>maven-mule-plugin</artifactId><version>1.9</version><extensions>true</extensions><configuration><copyToAppsDirectory>false</copyToAppsDirectory></configuration></plugin></plugins></build>
</project>

这里没有什么特别的。 除了必要的依赖关系之外,我还添加了maven-mule-plugin,以便可以创建“ mule”打包类型并从IDE运行Mule。
有了此Maven pom,我们可以创建以下两个Mule配置。 一个用于测试交易的Mule流:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"version="EE-3.4.1"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd"><flow name="MainFlow"><inbound-endpoint ref="event-queue" /><logger category="net.pascalalma.demo.MainFlow" level="INFO" message="Received message from activeMQ" /><scripting:component><scripting:script engine="Groovy">throw new Exception('Soap Fault Response detected')</scripting:script></scripting:component><outbound-endpoint ref="result-queue" /></flow>
</mule>

在此流程中,我们从入站端点接收到一条消息,记录一条消息并引发异常,然后将该消息放入下一个队列。 如我们所见,我没有添加任何异常处理程序。 端点和连接器的配置如下所示:

<?xml version="1.0" encoding="UTF-8"?><mule xmlns="http://www.mulesoft.org/schema/mule/core"xmlns:jms="http://www.mulesoft.org/schema/mule/jms"xmlns:spring="http://www.springframework.org/schema/beans"version="EE-3.4.1"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsdhttp://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd"><spring:bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy"><spring:property name="maximumRedeliveries" value="5"/><spring:property name="initialRedeliveryDelay" value="500"/><spring:property name="maximumRedeliveryDelay" value="10000"/><spring:property name="useExponentialBackOff" value="false"/><spring:property name="backOffMultiplier" value="3"/></spring:bean><!-- ActiveMQ Connection factory --><spring:bean id="amqFactory" class="org.apache.activemq.ActiveMQConnectionFactory" lazy-init="true"><spring:property name="brokerURL" value="tcp://localhost:61616" /><spring:property name="redeliveryPolicy" ref="redeliveryPolicy" /></spring:bean><jms:activemq-connector name="activeMqConnector"connectionFactory-ref="amqFactory"persistentDelivery="true"numberOfConcurrentTransactedReceivers="2"specification="1.1" /><jms:endpoint name="event-queue" connector-ref="activeMqConnector" queue="event-queue" ><jms:transaction action="ALWAYS_BEGIN" /></jms:endpoint><jms:endpoint name="result-queue" connector-ref="activeMqConnector" queue="result-queue" ><jms:transaction action="ALWAYS_JOIN" /></jms:endpoint>
</mule>

我为ActiveMQ连接工厂定义了一个Spring bean,并为该工厂的重新交付策略定义了一个Spring bean。 使用此重新分发策略,我们可以配置当原始尝试失败时,Mule应该重试处理队列中消息的频率。 重新交付策略中的一个不错的功能是“ backOffMultiplier”和“ useExponentialBackOff”组合。 使用这些选项,您可以使两次重新交付尝试之间的间隔成倍增加,直到达到'maximumRedeliveryDelay'。 在那种情况下,M子将等待“ maximumRedeliveryDelay”等待下一次尝试。

因此,使用这些配置,我们可以创建一个Mule测试类并运行它。 测试类如下所示:

package net.pascalalma.demo;import org.junit.Test;
import org.mule.DefaultMuleMessage;
import org.mule.api.MuleMessage;
import org.mule.module.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;public class TransactionFlowTest extends FunctionalTestCase {@Overrideprotected String getConfigResources() {return "app/test-flow.xml, app/test-endpoints.xml";}@Testpublic void testError() throws Exception {MuleClient client = new MuleClient(muleContext);MuleMessage inMsg = new DefaultMuleMessage("<txt>Some message</txt>", muleContext);client.dispatch("event-queue", inMsg);// Give Mule the chance to redeliver the messageThread.sleep(4000);}
}

如果我们运行此测试,您将在日志中看到如下消息:

Exception stack is:
1. "Message with id "ID:Pascals-MacBook-Pro-2.local-59158-1406440948059-1:1:3:1:1" has been redelivered 3 times on endpoint "jms://event-queue", which exceeds the maxRedelivery setting of 0 on the connector "activeMqConnector". Message payload is of type: ActiveMQTextMessage (org.mule.transport.jms.redelivery.MessageRedeliveredException)org.mule.transport.jms.redelivery.JmsXRedeliveryHandler:87 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/jms/redelivery/MessageRedeliveredException.html)

如果现在我们切换到ActiveMQ控制台 ,可以通过http:// localhost:8161进行默认本地安装,则可以看到以下队列:
截图-2014-07-27-10-08-09 不出所料,我们看到正在创建两个队列,事件队列为空,默认的ActiveMQ.DLQ包含我们的消息: 截图-2014-07-27-10-13-54

正如您可以想象的那样,为每个队列使用一个特定的DLQ而不是一个包含各种无法传递的消息的DLQ可能很方便。 幸运的是,这很容易在ActiveMQ中配置。 只需将以下内容放在“ $ ACTIVEMQ_HOME / conf”文件夹中的“ activemq.xml”文件中。

<!-- Set the following policy on all queues using the '>' wildcard -->
<policyEntry queue=">"><deadLetterStrategy><individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" /></deadLetterStrategy>
</policyEntry>

如果现在重新启动ActiveMQ,请删除现有队列并重新运行测试,我们将看到以下结果:
screenshot-2014-07-27-10-29-22 因此,使用此设置,每个队列都有自己的DLQ。 有关这些ActieMQ设置的更多选项,请参见此处 。 通过本文中创建的Mule流,可以轻松测试和使用这些设置。

翻译自: https://www.javacodegeeks.com/2014/07/mule-esb-activemq-and-the-dlq.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/362890.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

JS设计模式(2)策略模式

什么是策略模式&#xff1f; 定义&#xff1a;根据不同参数可以命中不同的策略 主要解决&#xff1a;在有多种算法相似的情况下&#xff0c;使用 if...else 所带来的复杂和难以维护。 何时使用&#xff1a;有许多种情况&#xff0c;而区分它们的只是他们直接的行为。 如何解…

C#中使用多线程访问Winform问题解决方案

我们在做winform应用的时候&#xff0c;大部分情况下都会碰到使用多线程控制界面上控件信息的问题。然而我们并不能用传统方法来做这个问题&#xff0c;下面我将详细的介绍。 首先来看传统方法&#xff1a; public partial class Form1 : Form{public Form1(){InitializeCompon…

Choose and Divide UVa 10375

题目大意&#xff1a;给出p,q,r,s&#xff0c;求组合数C(p,q)/C(r,s) 题目思路&#xff1a; 化简得到&#xff1a;原式等价于(p!(r-s)!s!) / (r!(p-q)!q!) 由算数基本定理可知任意一个正整数可被唯一分解为素数幂乘积的形式&#xff0c;将分子分母分解后&#xff0c;进行约分即…

在Java中避免空检查

对于Java开发人员&#xff08;从初级到专家&#xff09;最糟糕的噩梦之一是空对象引用检查。 我很确定您已经看过几次这样的代码&#xff1a; public void addAddressToCustomer(Customer customer, Address newAddress){if ( cutomer null || newAddress null)return;if ( …

Linux sudo 详解

简单的说&#xff0c;sudo 是一种权限管理机制&#xff0c;管理员可以授权于一些普通用户去执行一些 root 执行的操作&#xff0c;而不需要知道 root 的密码。严谨些说&#xff0c;sudo 允许一个已授权用户以超级用户或者其它用户的角色运行一个命令。当然&#xff0c;能做什么…

echarts自定义图例legend文字和样式

话不多说&#xff0c;先上效果图。 要完成这个图并不难&#xff0c;主要是下面那个图例比较难&#xff0c;需要定制。 让我们从官方文档找找思路&#xff0c;官方文档关于legend.formatter是这样的&#xff1a;链接在这 难点在于&#xff1a; 1.这里的图例文本包含两个变量&am…

DataGridView常见用法和FAQ汇总

前段时间在项目中用到了WinForm&#xff0c;其中最复杂的控件当属DataGridView了&#xff0c;特别喜欢它那高度的可配置性(提供了大量的属性&#xff0c;方法和事件)、丰富的内置列类型&#xff0c;而且易于扩展&#xff0c;对性能问题也提供了良好的解决方案。不过最初看着它那…

信息的Raid存储方式,更安全的保障,更花钱的保障!

raid0 就是把多个&#xff08;最少2个&#xff09;硬盘合并成1个逻辑盘使用&#xff0c;数据读写时对各硬盘同时操作&#xff0c;不同硬盘写入不同数据&#xff0c;速度快。  raid1就是同时对2个硬盘读写&#xff08;同样的数据&#xff09;。强调数据的安全性。比较浪费。 …

Java调试器和超时

在代码中存在超时的情况下如何使用调试器。 我的调试器王国&#xff01; 因此&#xff0c;您一直忙于编写一个项目&#xff0c;一切顺利&#xff0c;直到出现错误为止。 您可以进入开发人员的工具箱&#xff0c;然后拔出调试器。 很棒–您可以设置断点&#xff0c;可以在发生异…

【题解】整理书本

题目描述 小A想把他满屋子的书整理一下。书本分成若干堆。每一堆的书本都有质量w和价值v。小A的任务是将所有书合成一堆。因为小A认为合并i&#xff0c;j两堆的书所需要的力为w[i]-v[i]w[j]-v[j]。合并后的书堆的质量和价值均为合并前两堆书的质量和价值的总和。也就是说&#…

C#正则表达式编程(二):Regex类用法

上一篇讲述了在C#中有关正则表达式的类之间的关系&#xff0c;以及它们的方法&#xff0c;这一篇主要是将Regex这个类的用法的&#xff0c;关于Match及MatchCollection类会在下一篇讲到。对于正则表达式的应用&#xff0c;基本上可以分为验证、提取、分割和替换。仅仅利用Regex…

浏览器记住密码的自动填充Input问题完美解决方案

1、input 前from和input占位隐藏 <form style"width:0;height:0;display:none;"><input type"password" /></form><input type"password" style"width:0;height:0;display:none;" /> 2、input autocomplete&…

Java数字格式

当我看到其他人编写不必要的Java代码并且由于缺乏对已经提供所需功能的JDK类的了解而编写了不必要的Java代码时&#xff0c;我会想到很多次。 这样的一个例子是时间相关的常量的使用硬编码值的写入&#xff0c;如60 &#xff0c; 24 &#xff0c; 1440 &#xff0c;和86400时TI…

数据模型设计

数据&#xff1a;是符号。例如 张三 模型&#xff1a;现实世界事与物特征的抽象与模拟。如飞机模型、空气动力模型。 数据模型&#xff1a;通过对现实世界的事与物主要特征的分析、抽象&#xff0c;为信息系统的实施提供数据存取的数据结构以及相应的约束。 数据模型的要素由操…

优课在线 嵌入式系统(胡威)2018春季测验 参考解析

一、单选题 (共 20.00 分) μCOS-II操作系统属于&#xff08; &#xff09;。 A.一般实时操作系统 B.非嵌入式实时操作系统 C.占先式实时操作系统 D.非占先式实时操作系统 正确答案&#xff1a;C 寄存器R13除了可以做通用寄存器外&#xff0c;还可以做&#xff08; &#xff0…

JBoss Wildfly 8.1上的HawtIO

HawtIO为基于JVM的中间件提供了令人赞叹的视觉效果。 它是应用程序的统一控制台&#xff0c;否则将不得不构建自己的糟糕的Web控制台。 老实说&#xff0c;它们的构建方式各不相同&#xff0c;技术不同&#xff0c;用户体验不同&#xff0c;并且都围绕一种可怕的方式来尝试在QA…

Maven打包时去掉项目版本号

Maven打包时去掉项目版本号 Maven打包后&#xff0c;jar或war文件名里带有版本号信息&#xff0c;如projectname0.0.1-SNAPSHOT.jar等&#xff0c;怎么去掉呢&#xff1f; 解决办法&#xff1a; 打开项目pom.xml文件&#xff0c;在<build> </build>标签内加入如下…

jsp实现上一页下一页翻页功能

前段时间一直忙于期末考试和找实习&#xff0c;好久没写博客了。 这段时间做了个小项目&#xff0c;包含了翻页和富文本编辑器Ueditor的两个知识点,Ueditor玩的还不是很深&#xff0c;打算玩深后再写篇博客。 要实现翻页功能&#xff0c;只需要设置一个pageIndex即可&#xf…

学习笔记之postgresql

/*************************************************************************创建人&#xff1a;LYK 创建时间&#xff1a;2019/05/05 14:47IDE: vs2013 库版本&#xff1a;32位 静态库数据库管理平台 pgAdmin III -- postgresql 注意事项&#xff1a;1&#xff0c;添加头文件…

Delphi关于多线程同步的一些方法

(注&#xff1a;本文为转载 http://hi.baidu.com/navy1130/blog/item/468fcdc448794fce38db49ee.html)线程是进程内一个相对独立的、可调度的执行单元。一个应用可以有一个主线程&#xff0c;一个主线程可以有多个子线程&#xff0c;子线程还可以有自己的子线程&#xff0c;这…