Requirements
Banking comes with a docker-compose file which will allow you to run everything locally without the need to install the dependencies. There are however, a few tasks that need to be run in order to set up the database.
Setup
The first thing you need to do is copy the .env.sample
to .env
in the root
of the project. You will need to amend the KAFKA variable to point the ip address
where you are running Kafka, see Kafka below for more details on running a local
Kafka service.
docker-compose up -d
docker-compose run web rake db:create
docker-compose run web rake db:migrate
This will boot up several docker containers. An overview of the containers
An overview of what each of these does:
Container | Description |
---|---|
db | Runs a PostgreSQL database |
web | Runs a Ruby on Rails application, this is the API |
rabbitmq | Runs RabbitMQ server |
redis | Runs a redis service |
sneakers | Runs several workers, consumes/produces messages on rabbitmq and queues on redis |
kafka_consumer | Consumes messages from kafka |
fake-absa | A fake ABSA server |
Note on kafka_consumer and fake-absa
Kafka itself is not part of the docker-compose file. You will need to run Kafka independantly. The kafka_consumer container will attempt to connect to kafka on the host machine. Fake Absa will need to connect to the database, so on your initial docker-compose up -d fake-absa container will error out. After performing migrations you can run
docker-compose up -d fake-absa
. See below for more details.
Kafka
We can connect directly to the Phoenix
kafka service running on your localhost,
alternatively if you would like to run banking without running Phoenix
you can
perform the following actions.
To start kafka you can clone the following repo
git clone git@github.com:wurstmeister/kafka-docker.git
vim docker-compose-single-broker.yml
Replace as followes:
KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100
set to:
KAFKA_ADVERTISED_HOST_NAME: <YOUR LOCAL IP>
docker-compose -f docker-compose-single-broker.yml up -d
To test that it is up, telnet 127.0.0.1 9092
Now we can boot up the banking kafka consumer
NB: From the perspective of the kafka_consumer container, 127.0.0.1 will only point to itself. You need to ensure that your .env KAFKA variable is pointing to your host machines local ip address: ie: 10.0.0.100. Sadly docker.for.mac.localhost does not work...
You can start the kafka_consumer by running
docker-compose up -d kafka_consumer
Fake ABSA
We have a fake ABSA server which will take INPUT files and automatically generate a REPLY file. It is rather rudimentary at this stage but perfect for testing the workflow of payments being made.
The Fake ABSA server does need some basic setup in order for it to work correctly. You can run the following commands to get it going.
docker-compose run web rake absa:setup
docker-compose run web rake absa:start_workflow
Setup will create the credit and statement service needed. Start workflow will create the necessary RabbitMQ Queues for work to begin processing. You can then begin emitting kafka events or querything the api.
Initially your fake-absa service may not be running due to the database not existing. You should now be able to bring it up running
docker-compose up -d fake-absa
Congrats. We can now run a proper test.
We are going to push an event onto the stream and see what banking does. Let's use
the fnx command line application. If you have it installed locally you can run
fnx
, otherwise cd into the fnx-data
directory and run bundle exec bin/fnx
First check that we have Kafka setup.
bundle exec bin/fnx config settings
You can run bundle exec bin/fnx config set_kafka localhost:9092
Since fnx is run from your host machine localhost/127.0.0.1 is fine.
We can now listen to the topics
bundle exec bin/fnx banking listen
Open a new terminal and let's create an event using fnx. The following event will create a party and a payment of a random amount to that party.
bundle exec bin/fnx banking play_event
Assuming you have the fake-absa service running, it will create an input file and automatically generate a reply file with an accepted status.
We can now run a bank statement importer which will create several random incoming payments along with verified requests that were accepted.
docker-compose run web rake absa:import_statement