Skip to content

jian-feng/restdsl-sql-sample3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restdsl-sql-sample3

This project is used to demonstrate how to use rollback/commit and ErrorHandler within transactional camel route.

Detailed explanation is in Japanese only, and can be found at description.adoc.

To prepare user, db and table

create database testdb;
GRANT ALL PRIVILEGES ON testdb.* TO 'test'@'%' IDENTIFIED BY 'test';
GRANT ALL PRIVILEGES ON testdb.* TO 'test'@'localhost' IDENTIFIED BY 'test';
use testdb;

CREATE TABLE demo
(
id INTEGER,
name TEXT,
datetime DATETIME,
PRIMARY KEY (id)
) COMMENT='this is my test table';

To run the project

execute the following Maven goal

mvn camel:run

RESTクライアントの実行例

  • HTTP POST - createSample

createSampleは、Body(HashMap)のidをSQL内でInsert部で使用します。

curl -X POST -H 'Content-type: application/json' -d '{"id":"2"}' localhost:9000/private-api/v1/sample
  • HTTP PUT - updateSample

updateSampleは、Body(HashMap)のidをSQL内でUpdateで使用しますが、 Process2のExceptionによって、ロールバックされることを確認する目的です。

curl -X PUT -H 'Content-type: application/json' -d '{"id":"2"}' localhost:9000/private-api/v1/sample

実行結果

ログには以下のように出力されます。

updateSample                   INFO  Excec updateSample 2
updateSample                   INFO  Catch Exception of java.lang.RuntimeException: this is for rollback test.
DeadLetterChannel              WARN  Rollback (MessageId: ID-JFENG-MP-64075-1507111792224-0-2 …
CommonErrorHandler             ERROR Exchange[Id: ID-JFENG-MP-64075-1507111792224-0-1 …
CommonErrorHandler             INFO  This is CommonErrorHandler: body={id=2}

About

demonstrate how to use rollback/commit and ErrorHandler within transactional camel route.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages