そごうソフトウェア研究所

SOA、開発プロセス、ITアーキテクチャなどについて書いています。Twitterやってます@rsogo

Mule ESB 3.7のエラーハンドリング

Muleではフローの実行中にエラーが発生したときのエラーハンドリングの仕組みを持っています。

いくつかの例外のタイプが用意されています。これらの例外ハンドリングの定義を含んだ親Flowを実行中に発生した例外が対象です。

この中で実案件では、Choice exceptionの理解は必須でかなと思います。 発生したエラーの内容に合わせて、実装するハンドリングを切り替えます。 実際のエラーハンドリングはCatch exception strategyや、Rollback exception strategyで書いていく。

構造を単純に書くとこんな感じ。

<flow>
    <リクエストの受取/>
    <メッセージ変換など/>
    <連携先の呼び出し/>
    <応答メッセージの編集/>
    <choice-exception-strategy>
        <例外Xが起こったときのハンドリング/>
        <例外Yが起こったときのハンドリング/>
    </choice-exception-strategy>
</flow>

実際のサンプルです。

Mule エラーハンドリング・サンプル

例えば、上の定義だと、データベースの接続ができなかった場合は次のエラーが発生しますが、その時、「500 Internal Server Error」をクライアントに返します。

org.mule.module.db.internal.domain.connection.ConnectionCreationException: java.sql.SQLException: Cannot get connection for URL

Select文のWhere句に使用する値をQuery Parameterから取得しています。そこに不正な文字列が使用された場合などにjava.sql.SQLSyntaxErrorExceptionが発生しますが、「400 Bad Request」をクライアントに返します。

これでよく分からないエラーメッセージが返ってくるよりも ぐっと、使い易いWebサービスになりました。

参照情報

マニュアル

Error Handling - Current Mule Documentation

公式サンプル

anypoint-examples/implementing-a-choice-exception-strategy at 3.7 · mulesoft/anypoint-examples · GitHub

Mule ESB 3.7のDatabase Connectorを試す1(設定とSELECT)

デプロイ

mule-config.xmlをappsの下に作ったdatabaseフォルダに置きます。

$ pwd
/Users/rsogo/work/mule-standalone-3.7.0/apps/database
$ ls
mule-config.xml

gist.github.com

デプロイ時ログ

おぉ、成功。

*******************************************************************************************************
*            - - + APPLICATION + - -            *       - - + DOMAIN + - -       * - - + STATUS + - - *
*******************************************************************************************************
* default                                       * default                        * DEPLOYED           *
* database                                      * default                        * DEPLOYED           *
*******************************************************************************************************

JDBC Driverの配置

  • Database Driverになにもやってない状態でhttp://localhost:8081/にアクセスすると次のようなエラーがでた。
org.mule.module.db.internal.domain.connection.ConnectionCreationException: java.sql.SQLException: Error trying to load driver: oracle.jdbc.Driver : oracle.jdbc.Driver (java.sql.SQLException). Message payload is of type: NullPayload

OracleからJDBC Driverをダウンロードする。

Oracle Database 12c Release 1 JDBC Driver Downloads

自分の環境はJDK1.7を使っているので、ojdbc7.jar

{MULE_HOME}/lib/user/配下に置く。

$ ls lib/user/
README.txt          mule-tests-functional-3.7.0.jar xmlunit-1.5.jar
junit-4.11.jar          ojdbc7.jar

StackOverflowかどこかに{MULE_HOME}/lib/mule/に置けって言っている人がいるけど、それだと動かなかった。

  • DriverはOKで、コネクションが確立できない場合のログ。
org.mule.module.db.internal.domain.connection.ConnectionCreationException: java.sql.SQLException: Cannot get connection for URL jdbc:oracle:thin:{User}/{Password}@localhost:{SID} : No suitable driver found for jdbc:oracle:thin:{User}/{Password}@localhost:{SID} (java.sql.SQLException). Message payload is of type: NullPayload

実行

Muleを実行しているマシンのhttp://locahost:8081/にアクセスしてみる。 上手く行っていると、データベースに検索した結果がJSONに変換されたレスポンスが見られる。

続きを次のエントリで書いています。 begirama.hatenablog.com

Mule ESB 3.6起動

Mule 3.7での同エントリを書きました。

Mule ESB 3.7起動 - そごうソフトウェア研究所


Mule ESB 3.6をしばらく触ってみようと思います。 環境はOSX 10.10.4です。

Mule ESB 3.6ダウンロード

今回はMule Community Editionでできることを調査しようと思います。 でもマニュアルにあるMule CEのダウンロードのリンクから移動しても、このEnterprise版のダウンロードページに飛ばされてしまいます。要確認だけど、取りあえず、こちらに含まれるStandaloneだけを使います。

Try Mule | MuleSoft

Muleの起動

mmc-distribution-mule-console-bundle-3.6.1.zipを解凍します。

MMCなども入っていますが、Runtimeモジュールのbinフォルダに移動します。

$ cd mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/bin

起動コマンドを実行します。 $ ./mule

起動ログ

いろんなソフトウェアをやっているとログは読み物だなと、思います。 ログを根気よく読むとソフトウェアが何をやっているのかが分かる。

$ ./mule 
MULE_HOME is set to /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1
Running in console (foreground) mode by default, use Ctrl-C to exit...
MULE_HOME is set to /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Running Mule Enterprise Edition...
--> Wrapper Started as Console
Java Service Wrapper Standard Edition 32-bit 3.5.19
  Copyright (C) 1999-2013 Tanuki Software, Ltd. All Rights Reserved.
    http://wrapper.tanukisoftware.com
  Licensed to mulesoft.com for Mule ESB Enterprise Edition

Launching a JVM...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

Valid license key --> Evaluation = true, Expiration Date = Mon Aug 03 00:00:00 JST 2015, Contact Name = MuleSource Support, Contact Email Address = support@mulesource.com, Contact Telephone = support@mulesource.com, Contact Company = MuleSource, Contact Country = US, Entitlements = 

Starting the Mule Container...
WrapperManager: Initializing...
INFO  2015-07-04 06:56:00,050 [WrapperListener_start_runner] org.mule.module.launcher.MuleContainer: 
**********************************************************************
* Mule ESB and Integration Platform                                  *
* Version: 3.6.1 Build: 0758df2b                                     *
* MuleSoft, Inc.                                                     *
* For more information go to                                         *
* http://www.mulesoft.com/mule-esb-enterprise                        *
*                                                                    *
* Server started: 15/07/04 6:56                                      *
* JDK: 1.7.0_71 (mixed mode)                                         *
* OS: Mac OS X (10.10.4, x86_64)                                     *
* Host: Ryohei-no-MacBook-Pro.local (192.168.11.5)                   *
**********************************************************************
INFO  2015-07-04 06:56:00,089 [WrapperListener_start_runner] org.mule.module.launcher.coreextension.DefaultMuleCoreExtensionManager: Initializing core extensions
INFO  2015-07-04 06:56:00,125 [WrapperListener_start_runner] com.mulesoft.mule.cluster.hazelcast.config.ClusterTicketFileLoader: /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/.mule/mule-cluster.properties (No such file or directory)
WARN  2015-07-04 06:56:00,131 [WrapperListener_start_runner] com.mulesoft.mule.cluster.boot.ClusterCoreExtension: No cluster ID was specified -- High Availability will be disabled:
INFO  2015-07-04 06:56:00,250 [WrapperListener_start_runner] com.mulesoft.mule.plugin.manager.MulePluginManager: Registering plugin: mule-plugin-debugger-3.6.0-RC1
INFO  2015-07-04 06:56:00,274 [WrapperListener_start_runner] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Mule Agent Core Extension'. Object is: AgentCoreExtension
INFO  2015-07-04 06:56:00,453 [WrapperListener_start_runner] org.mule.lifecycle.AbstractLifecycleManager: Initialising RegistryBroker
WARN  2015-07-04 06:56:00,721 [WrapperListener_start_runner] org.mule.module.ognl.expression.OgnlExpressionEvaluator: OGNL module is deprecated and will be removed in Mule 4.0. Use MEL expressions instead.
INFO  2015-07-04 06:56:01,261 [WrapperListener_start_runner] org.mule.config.processors.DecoratingAnnotatedServiceProcessor: org.mule.config.AnnotationsParserFactory implementation not found in registry, annotations not enabled
INFO  2015-07-04 06:56:01,863 [WrapperListener_start_runner] org.mule.util.journal.TransactionJournal: Using files for tx logs /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-tx-log/tx1.log and /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-tx-log/tx2.log
INFO  2015-07-04 06:56:01,883 [WrapperListener_start_runner] org.mule.util.journal.TransactionJournal: Using files for tx logs /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-xa-tx-log/tx1.log and /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-xa-tx-log/tx2.log
INFO  2015-07-04 06:56:01,885 [WrapperListener_start_runner] org.mule.util.journal.TransactionJournal: Using files for tx logs /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-tx-log/tx1.log and /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-tx-log/tx2.log
INFO  2015-07-04 06:56:01,886 [WrapperListener_start_runner] org.mule.util.journal.TransactionJournal: Using files for tx logs /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-xa-tx-log/tx1.log and /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/./.mule/.agent/queue-xa-tx-log/tx2.log
INFO  2015-07-04 06:56:01,945 [WrapperListener_start_runner] org.mule.lifecycle.AbstractLifecycleManager: Initialising model: _muleSystemModel
INFO  2015-07-04 06:56:02,113 [WrapperListener_start_runner] org.mule.module.launcher.coreextension.DefaultMuleCoreExtensionManager: Starting core extensions
INFO  2015-07-04 06:56:02,113 [WrapperListener_start_runner] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Mule Agent Core Extension'. Object is: AgentCoreExtension
INFO  2015-07-04 06:56:02,114 [WrapperListener_start_runner] org.mule.util.queue.QueueXaResourceManager: Starting ResourceManager
INFO  2015-07-04 06:56:02,114 [WrapperListener_start_runner] org.mule.util.queue.QueueXaResourceManager: Started ResourceManager
INFO  2015-07-04 06:56:02,128 [WrapperListener_start_runner] org.mule.modules.oauth2.provider.agents.DefaultSplashScreenAgent: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ DevKit Extensions (0) used in this application 
                             +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2015-07-04 06:56:02,129 [WrapperListener_start_runner] org.mule.lifecycle.AbstractLifecycleManager: Starting model: _muleSystemModel
INFO  2015-07-04 06:56:02,137 [WrapperListener_start_runner] org.mule.module.management.agent.WrapperManagerAgent: Mule is embedded in a container already launched by a wrapper.Duplicates will not be registered. Use the org.tanukisoftware.wrapper:type=WrapperManager MBean instead for control.
INFO  2015-07-04 06:56:02,153 [WrapperListener_start_runner] org.mule.DefaultMuleContext: 
**********************************************************************
* Application: .agent                                                *
* OS encoding: /, Mule encoding: UTF-8                               *
*                                                                    *
* Agents Running:                                                    *
*   DevKit Extension Information                                     *
*   Batch module default engine                                      *
*   Clustering Agent                                                 *
*   JMX Agent                                                        *
**********************************************************************
INFO  2015-07-04 06:56:02,158 [WrapperListener_start_runner] org.eclipse.jetty.server.Server: jetty-9.0.7.v20131107
INFO  2015-07-04 06:56:02,371 [WrapperListener_start_runner] /mmc-support: Initializing Spring root WebApplicationContext
INFO  2015-07-04 06:56:02,371 [WrapperListener_start_runner] org.springframework.web.context.ContextLoader: Root WebApplicationContext: initialization started
INFO  2015-07-04 06:56:02,515 [WrapperListener_start_runner] org.springframework.web.context.support.XmlWebApplicationContext: Refreshing Root WebApplicationContext: startup date [Sat Jul 04 06:56:02 JST 2015]; root of context hierarchy
INFO  2015-07-04 06:56:03,163 [WrapperListener_start_runner] org.springframework.web.context.support.ServletContextAttributeExporter: Exported ServletContext attribute with name 'discoveryEngine'
INFO  2015-07-04 06:56:03,472 [WrapperListener_start_runner] org.quartz.core.SchedulerSignalerImpl: Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
INFO  2015-07-04 06:56:03,473 [WrapperListener_start_runner] org.quartz.core.QuartzScheduler: Quartz Scheduler v.1.8.5 created.
INFO  2015-07-04 06:56:03,475 [WrapperListener_start_runner] org.quartz.simpl.RAMJobStore: RAMJobStore initialized.
INFO  2015-07-04 06:56:03,476 [WrapperListener_start_runner] org.quartz.core.QuartzScheduler: Scheduler meta-data: Quartz Scheduler (v1.8.5) 'scheduler' with instanceId 'NON_CLUSTERED'
  Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
  NOT STARTED.
  Currently in standby mode.
  Number of jobs executed: 0
  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

INFO  2015-07-04 06:56:03,477 [WrapperListener_start_runner] org.quartz.impl.StdSchedulerFactory: Quartz scheduler 'scheduler' initialized from an externally provided properties instance.
INFO  2015-07-04 06:56:03,477 [WrapperListener_start_runner] org.quartz.impl.StdSchedulerFactory: Quartz scheduler version: 1.8.5
INFO  2015-07-04 06:56:03,479 [WrapperListener_start_runner] org.quartz.core.QuartzScheduler: JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@5e8db999
INFO  2015-07-04 06:56:03,555 [WrapperListener_start_runner] org.springframework.context.support.DefaultLifecycleProcessor: Starting beans in phase 2147483647
INFO  2015-07-04 06:56:03,555 [WrapperListener_start_runner] org.springframework.scheduling.quartz.SchedulerFactoryBean: Starting Quartz Scheduler now
INFO  2015-07-04 06:56:03,556 [WrapperListener_start_runner] org.quartz.core.QuartzScheduler: Scheduler scheduler_$_NON_CLUSTERED started.
INFO  2015-07-04 06:56:03,569 [WrapperListener_start_runner] org.springframework.web.context.ContextLoader: Root WebApplicationContext: initialization completed in 1197 ms
INFO  2015-07-04 06:56:03,651 [WrapperListener_start_runner] /mmc-support: Initializing Spring FrameworkServlet 'api'
INFO  2015-07-04 06:56:03,651 [WrapperListener_start_runner] org.springframework.web.servlet.DispatcherServlet: FrameworkServlet 'api': initialization started
INFO  2015-07-04 06:56:03,657 [WrapperListener_start_runner] org.springframework.web.context.support.XmlWebApplicationContext: Refreshing WebApplicationContext for namespace 'api-servlet': startup date [Sat Jul 04 06:56:03 JST 2015]; parent: Root WebApplicationContext
INFO  2015-07-04 06:56:03,900 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/muleContextService] onto handler '/v3/muleContextService'
INFO  2015-07-04 06:56:03,901 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/muleConfigurationService] onto handler '/v3/muleConfigurationService'
INFO  2015-07-04 06:56:03,901 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/wrapperManagerService] onto handler '/v3/wrapperManagerService'
INFO  2015-07-04 06:56:03,901 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/auditService] onto handler '/v3/auditService'
INFO  2015-07-04 06:56:03,901 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/flowService] onto handler '/v3/flowService'
INFO  2015-07-04 06:56:03,902 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3_1/clusterNodeService] onto handler '/v3_1/clusterNodeService'
INFO  2015-07-04 06:56:03,902 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/trackingService] onto handler '/v3/trackingService'
INFO  2015-07-04 06:56:03,902 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/systemFileService] onto handler '/v1/systemFileService'
INFO  2015-07-04 06:56:03,902 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/muleFileService] onto handler '/v1/muleFileService'
INFO  2015-07-04 06:56:03,902 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/threadsService] onto handler '/v1/threadsService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/memoryService] onto handler '/v1/memoryService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/statusService] onto handler '/v3/statusService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/jmxService] onto handler '/v1/jmxService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/poolService] onto handler '/v3/poolService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/statisticsService] onto handler '/v1/statisticsService'
INFO  2015-07-04 06:56:03,903 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/statisticsService] onto handler '/v3/statisticsService'
INFO  2015-07-04 06:56:03,904 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/systemService] onto handler '/v3/systemService'
INFO  2015-07-04 06:56:03,904 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/alertService] onto handler '/v1/alertService'
INFO  2015-07-04 06:56:03,904 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v1/slaService] onto handler '/v1/slaService'
INFO  2015-07-04 06:56:03,904 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/applicationService] onto handler '/v3/applicationService'
INFO  2015-07-04 06:56:03,904 [WrapperListener_start_runner] org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping: Mapped URL path [/v3/applicationLogService] onto handler '/v3/applicationLogService'
INFO  2015-07-04 06:56:04,122 [WrapperListener_start_runner] org.springframework.web.servlet.DispatcherServlet: FrameworkServlet 'api': initialization completed in 471 ms
INFO  2015-07-04 06:56:04,127 [WrapperListener_start_runner] /mmc-support: AgentServlet: Starting MMC Agent.
INFO  2015-07-04 06:56:04,129 [WrapperListener_start_runner] /mmc-support: AgentServlet: Initialized com.mulesoft.mmc.agent.web.AgentServlet@f51d94d with ID c71a8cd9-dc7e-4750-bc51-d1faf204ceea


INFO  2015-07-04 06:56:10,825 [WrapperListener_start_runner] org.eclipse.jetty.server.handler.ContextHandler: Started o.e.j.w.WebAppContext@2046bc37{/mmc-support,jar:file:/Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/lib/mule/mmc-agent-impl-3.6.1.jar!/mmc-support-app,AVAILABLE}
INFO  2015-07-04 06:56:10,839 [WrapperListener_start_runner] org.eclipse.jetty.server.ServerConnector: Started ServerConnector@b094e09{HTTP/1.1}{0.0.0.0:7777}
INFO  2015-07-04 06:56:10,862 [WrapperListener_start_runner] org.eclipse.jetty.server.ServerConnector: Stopped ServerConnector@b094e09{HTTP/1.1}{0.0.0.0:7777}
INFO  2015-07-04 06:56:10,966 [WrapperListener_start_runner] org.eclipse.jetty.server.ServerConnector: Started ServerConnector@44e995bf{SSL-HTTP/1.1}{0.0.0.0:7777}
INFO  2015-07-04 06:56:10,967 [WrapperListener_start_runner] com.mulesoft.mmc.agent.AgentCoreExtension: Mule Agent Core Extension listening on (0.0.0.0:7777)
INFO  2015-07-04 06:56:10,972 [WrapperListener_start_runner] org.mule.module.launcher.DefaultArchiveDeployer: ================== New Exploded Artifact: default
INFO  2015-07-04 06:56:10,980 [WrapperListener_start_runner] org.mule.module.launcher.MuleSharedDomainClassLoader: Using domain dir /Users/rsogo/work/mmc-distribution-mule-console-bundle-3.6.1/mule-enterprise-3.6.1/domains/default for domain default
INFO  2015-07-04 06:56:11,077 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started domain 'default'                                 +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2015-07-04 06:56:11,079 [WrapperListener_start_runner] org.mule.module.launcher.DefaultArchiveDeployer: ================== New Exploded Artifact: default
INFO  2015-07-04 06:56:11,101 [WrapperListener_start_runner] org.mule.module.launcher.application.DefaultMuleApplication: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ New app 'default'                                        +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2015-07-04 06:56:12,140 [WrapperListener_start_runner] org.mule.module.launcher.MuleDeploymentService: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'default'                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2015-07-04 06:56:12,192 [WrapperListener_start_runner] org.mule.module.launcher.DeploymentDirectoryWatcher: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Mule is up and kicking (every 5000ms)                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2015-07-04 06:56:12,207 [WrapperListener_start_runner] org.mule.module.launcher.StartupSummaryDeploymentListener: 
**********************************************************************
*              - - + DOMAIN + - -               * - - + STATUS + - - *
**********************************************************************
* default                                       * DEPLOYED           *
**********************************************************************

*******************************************************************************************************
*            - - + APPLICATION + - -            *       - - + DOMAIN + - -       * - - + STATUS + - - *
*******************************************************************************************************
* default                                       * default                        * DEPLOYED           *
*******************************************************************************************************

Mule 3.5のセットアップとサンプルの実行

会社の方で公式ドキュメントして書くのだけど、ひとまずこちらに書いてみます。

目標は、取りあえずインストールして、実行してみるところまで。

インストール

使用可能な環境はここでチェック。OSはMuleがサポートしているJDKがサポートしていればOKっぽい。

http://www.mulesoft.org/documentation/display/current/Hardware+and+Software+Requirements

どんな構成にするか

デプロイモードを選択する。

http://www.mulesoft.org/documentation/display/current/Deployment+Scenarios

ここでいうデプロイメントとは、Mule自体の配置のこと。Mule上で動作するモジュールのデプロイメントではない。

MuleはAPサーバー上でも動かすことができるけど、基本はスタンドアローンでOK。

Mule Management Consoleって使うの?

http://www.mulesoft.org/documentation/display/current/Mule+Management+Console

いろいろな管理機能が提供される。Enterprise Editionが必要。

インストールの手順はこれの「Mule Community Runtime」のタブに従ってやればOK。基本、スタンドアローン構成ならZipを解凍するだけ。

http://www.mulesoft.org/documentation/display/current/Downloading+and+Launching+Mule+ESB+-+hid

  1. Javaセットアップ Javaをセットアップして、JAVA_HOME設定

export JAVA_HOME=/usr/java/jdk1.7.0_60/

  1. Muleセットアップ 解凍するだけ。まじ簡単。

bin/muleを実行で起動。終了するときはCtlr+C。

起動停止

$MULE_HOME\bin\mule.bat start|stop

起動オプションなんかは下記にまとまっている。

http://www.mulesoft.org/documentation/display/current/Starting+and+Stopping+Mule+ESB

自分で作ったモジュールを動かしてみよう

Anypont Studioを入れるとSampleが一緒に付いてくるから、それを実行してみましょう。

f:id:begirama:20140627084110p:plain

スタートページのOpen Sampleでサンプルの一覧が見られる。

f:id:begirama:20140627084119p:plain

まあ、最初はHelloWorldだろうと。

f:id:begirama:20140627084123p:plain

フロー定義の見た目はこんな感じ。 HTTPでリッスンして、文字列を返すだけのフロー。

取りあえず試すだけなら、Anypont Studioの中に埋め込みMuleが入っているのでプロジェクトを右クリックして、「Run AS-> Mule Application」でOK。

サーバー上のMuleへのデプロイは上記のURLの「Deploy on a Mule Enterprise Server」の通りにやればOK。

Anypont StudioでExportする

f:id:begirama:20140627084441p:plain

f:id:begirama:20140627084448p:plain

f:id:begirama:20140627084455p:plain

Muleへのデプロイ

Mule HOMEのappsフォルダにzipを置くだけ。 Muleがポーリングをしていて、しばらくするとzipが解凍されます。

[sogo@localhost mule-standalone-3.5.0]$ cd apps/
[sogo@localhost apps]$ ls
default  default-anchor.txt

appsフォルダにエクスポートしたhello-world.zipを置くと・・・・

[sogo@localhost apps]$ cp ~/hello-world.zip .
[sogo@localhost apps]$ ls
default  default-anchor.txt  hello-world.zip

しばらくするとzipが展開されてデプロイされている。

[sogo@localhost apps]$ ls
default  default-anchor.txt  hello-world  hello-world-anchor.txt

Muleのデプロイログ

同じタイミングでMule側のログには、サンプルアプリが置かれたことを検知して、インストールして起動した旨のログがでます。

INFO  2014-06-26 21:26:12,950 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.ArtifactArchiveInstaller: Exploding a Mule artifact archive: file:/home/sogo/mule/mule-standalone-3.5.0/apps/hello-world.zip
INFO  2014-06-26 21:26:13,008 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.application.DefaultMuleApplication: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ New app 'hello-world'                                    +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
INFO  2014-06-26 21:26:13,009 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.log4j.ArtifactAwareRepositorySelector: Found logging config for application 'hello-world' at 'file:/home/sogo/mule/mule-standalone-3.5.0/conf/log4j.properties'
INFO  2014-06-26 21:26:15,796 [Mule.app.deployer.monitor.1.thread.1] org.mule.module.launcher.MuleDeploymentService: 
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Started app 'hello-world'                                +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

いやー簡単ですね。

ESBの持つべき機能とは

ESBの教科書でもあるエンタープライズサービスバスにはESBの機能のパターンとしてVET(R)Oって言ってますね。
V:Varidate
E:Enrich
T:Transform
R:Route
O:Operate

僕もこれが最低必須ってことで理解してます。

hikiさんとこで教えてもらったエンタープライズ・サービス・バスの実装パターン
読んでみた。

エンタープライズ・サービス・バスの実装パターンの相関、モニタ、監査などなどの機能は、まあ、あったら便利ですよね。

逆に検索(ディスカバリー)なんかは、ESBでやんの!?という気もします。

あとは、異なるシステム間でそれぞれコードを持っているので、そのコード変換とか求められることが多いですよね。ここは結局、変換テーブルみたいなのを見に行くしかないのかなー??