Demo of usage PostgreSQL advisory locks.
-
Run Postgres server
$ docker run -d --name my-postgres -p 55432:5432 \ -e POSTGRES_PASSWORD=mysecretpassword postgres:12.5-alpine
-
Connect to Postgres server via command line interface:
$ docker exec -it my-postgres psql -U postgres
And run the following sql:
CREATE ROLE testuser WITH LOGIN PASSWORD 'P@ssw0rd1+'; CREATE DATABASE testdb WITH OWNER testuser;
-
Connect to Postgres server again:
$ docker exec -it my-postgres psql -d testdb -U testuser
And run the following sql:
CREATE TABLE messages ( id uuid NOT NULL, message text NOT NULL, status text NOT NULL, version int NOT NULL, CONSTRAINT messages_pk PRIMARY KEY (id) );
-
Build application using Maven:
$ mvn package
-
Run multiple instances of Consumer:
$ ./run-consumer.sh
-
Run Producer:
$ ./run-producer.sh