0% found this document useful (0 votes)
158 views6 pages

How To Setup Eventuate-Tram-Cdc Service Locally - by Erandika Harshani - Medium

The document describes how to set up the Eventuate-tram-cdc service locally. It involves installing Java, Zookeeper, Kafka, MySQL, creating databases and tables, configuring application properties, and starting the cdc service jar. It also provides a sample customer service application to demonstrate publishing events to the cdc service when data is inserted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views6 pages

How To Setup Eventuate-Tram-Cdc Service Locally - by Erandika Harshani - Medium

The document describes how to set up the Eventuate-tram-cdc service locally. It involves installing Java, Zookeeper, Kafka, MySQL, creating databases and tables, configuring application properties, and starting the cdc service jar. It also provides a sample customer service application to demonstrate publishing events to the cdc service when data is inserted.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

Get started Open in app

Erandika Harshani
12 Followers About Follow

How to setup Eventuate-tram-cdc Service


locally
Erandika Harshani Sep 21, 2019 · 3 min read

Eventuate Tram is a platform that solves the distributed data management problems
inherent in a microservice architecture. It’s for Java/Spring-based microservices that use
the traditional JDBC/JPA-based persistence model.- eventuate-tram

How to setup locally?


To set up the eventuate-tram-cdc service, download the cdc-service jar file first.

Before up the eventuate-tram-cdc-service, you have to do the following prerequisites.

1] Install java 8 or latest java version

2] Start your zookeeper and kafka services; use kafka_2.12–2.2.0 version. This package
has both zookeeper and kafka configuration files.

3] By default, eventuate works with mysql binlog. In that case, you have to enable mysql
binlog configuration. If you don’t want to enable mysql binlog, you can use
‘spring.profiles.active=EventuatePolling’ property in application.properties file. Start
mysql service.

4] Create eventuate database

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 1/6
5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

create database eventuate;


Get startedALL PRIVILEGES
GRANT Open in app ON eventuate.* TO 'mysqluser'@'%' WITH GRANT
OPTION;

5] Create tables in the eventuate database

USE eventuate;

DROP table IF EXISTS events;


DROP table IF EXISTS entities;
DROP table IF EXISTS snapshots;
DROP table IF EXISTS message;
DROP table IF EXISTS cdc_monitoring;

create table events (


event_id varchar(1000) PRIMARY KEY,
event_type varchar(1000),
event_data varchar(1000) NOT NULL,
entity_type VARCHAR(1000) NOT NULL,
entity_id VARCHAR(1000) NOT NULL,
triggering_event VARCHAR(1000),
metadata VARCHAR(1000),
published TINYINT DEFAULT 0
);

CREATE INDEX events_idx ON events(entity_type, entity_id, event_id);


CREATE INDEX events_published_idx ON events(published, event_id);

create table entities (


entity_type VARCHAR(1000),
entity_id VARCHAR(1000),
entity_version VARCHAR(1000) NOT NULL,
PRIMARY KEY(entity_type, entity_id)
);

CREATE INDEX entities_idx ON events(entity_type, entity_id);

create table snapshots (


entity_type VARCHAR(1000),
entity_id VARCHAR(1000),
entity_version VARCHAR(1000),
snapshot_type VARCHAR(1000) NOT NULL,
snapshot_json VARCHAR(1000) NOT NULL,
triggering_events VARCHAR(1000),
PRIMARY KEY(entity_type, entity_id, entity_version)
);

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 2/6
5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

CREATE TABLE message (


idstarted
Get varchar(767) NOT NULL,
Open in app
destination varchar(1000) NOT NULL,
headers varchar(1000) NOT NULL,
payload varchar(1000) NOT NULL,
published smallint(6) DEFAULT '0',
creation_time bigint(20) DEFAULT NULL,
PRIMARY KEY (id),
KEY message_published_idx (published,id)
);

create table received_messages (


consumer_id varchar(767) NOT NULL,
message_id varchar(767) NOT NULL,
creation_time bigint(20) DEFAULT NULL,
PRIMARY KEY (consumer_id, message_id)
);

create table cdc_monitoring (


reader_id VARCHAR(1000) PRIMARY KEY,
last_time BIGINT
);

You have to execute the following sql commands if you are going to use the newer
eventuate tram version(0.21.3.RELEASE).

CREATE TABLE offset_store(client_name VARCHAR(255) NOT NULL PRIMARY


KEY, serialized_offset VARCHAR(255));

ALTER TABLE received_messages MODIFY creation_time BIGINT;

6] Create application.properties file with the following configurations according to your


local environment.

spring.datasource.url=jdbc:mysql://localhost:3306/eventuate?
autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver.class.name=com.mysql.jdbc.Driver
eventuatelocal.kafka.bootstrap.servers=localhost:9092
eventuatelocal.zookeeper.connection.string=localhost:2181
eventuatelocal.cdc.db.user.name=root
eventuatelocal.cdc.db.password=password
eventuate.database.schema=eventuate

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 3/6
5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

eventuatelocal.cdc.source.table.name=MESSAGE
eventuate.cdc.type=EventuateTram
Get started Open in app
spring.profiles.active=EventuatePolling

eventuatelocal.cdc.read.old.debezium.db.offset.storage.topic=false
eventuatelocal.cdc.reader.name=customcdcreader
eventuatelocal.cdc.mysql.binlog.client.unique.id=1
eventuatelocal.cdc.offset.storage.topic.name=db.history.common
eventuatelocal.cdc.leadership.lock.path=/eventuatelocal/cdc/leader/1

Now you are eligible to up the tram-cdc service. Following is the command to start the
tram-cdc-service.

java -jar “<folder path>/eventuate-tram-cdc-mysql-service-


0.21.3.RELEASE.jar” --spring.config.location=“<folder
path>/application.properties”

From the console log, you can see whether eventuate-tram-cdc-service is up. After a
successful starting, you can use this service for your purposes.

Sample-Customer-Service
Sample Customer Service is used to publish events using eventuate-tram-cdc-service
when inserting customers to its database.

This repository is a spring-boot application. Clone and start the sample service and use
the following CURL to add customers to the database.

Request:

curl -X POST \
http://localhost:8085/customer_service/add_customer \
-H ‘content-type: application/json’ \
-d ‘{
“name”: “demo user”,
“email”: “[email protected]”,
“country”: “SL”
}’

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 4/6
5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

Response:
Get started Open in app

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
{
“customerId”: 1
}

After getting a successful response,

you can see your customer database is updated with your request payload;

eventuate MESSAGE table is also updated with the event and

if you execute kafka topic consume command with your event topic(this can find
from MESSAGE table destination column), it has a new record with your request.

References:

Eventuate Tram
Eventuate Tram is a platform that solves the distributed data
management problems inherent in a microservice…
eventuate.io

eventuate-tram/eventuate-tram-core
Maintain data consistency using sagas Implement commands that
update data in multiple microservices by using Sagas…
github.com

eventuate-tram/eventuate-tram-examples-customers-and-orders
This application demonstrates two key patterns: The application consists of three services:
Order Service - manages…
github.com

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 5/6
5/8/2021 How to setup Eventuate-tram-cdc Service locally | by Erandika Harshani | Medium

Get started Open in app

Eventuate Tram MySQL Kafka Spring Boot Java

About Write Help Legal

Get the Medium app

https://medium.com/@erandika_harshani/how-to-setup-eventuate-tram-framework-locally-b27f5ba36b87 6/6

You might also like