Skip to content

Commit

Permalink
Add concurrent environment for testing with multiple instances and
Browse files Browse the repository at this point in the history
logging improvements
  • Loading branch information
ktogias committed Jul 23, 2022
1 parent eaa8fa3 commit fff0ac3
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 5 deletions.
6 changes: 2 additions & 4 deletions dev/Application/Messaging/Impl/EventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ public function handle(Message $message, string $channel): void
if ($this->translator){
$message = $this->translator->translate($message);
}
echo "Handling message with body: "
.$message->getBody().", headers: "
.print_r($message->getHeaders(), true).", properties: "
.print_r($message->getProperties(), true)."\n";
echo "Handling message with id: ".$message->getProperties()['id']." from channel: ".$channel."...\n";
$this->store->add(message: $message, channel: $channel);
echo "Successfully added message to store.\n";
}

}
5 changes: 4 additions & 1 deletion dev/tests/features/bootstrap/PingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class PingContext implements Context
{
protected int $port;

protected string $host;

protected Curl $curl;

/**
Expand All @@ -34,6 +36,7 @@ public function __construct()
public function theServicePortIsDefined()
{
$this->port = getenv('HTTP_PORT');
$this->host = getenv('HTTP_HOST')?:'localhost';
}

/**
Expand All @@ -42,7 +45,7 @@ public function theServicePortIsDefined()
public function iDoHttpGet()
{
$this->curl = new Curl();
$this->curl->get('http://event-listener:'.$this->port);
$this->curl->get('http://'.$this->host.':'.$this->port);
}

/**
Expand Down
24 changes: 24 additions & 0 deletions ops/envs/concurrent/comp/.dist.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
COMPOSE_PROJECT_NAME=evdobe-event-listener
TIME_ZONE=Europe/Athens
HTTP_PORT=9501
MESSAGE_BROKER_HOST=kafka
MESSAGE_BROKER_PORT=29092
MESSAGE_CONSUMER_GROUP=my-event-listener
EVENT_CHANNEL_1=my-event-channel
EVENT_CHANNEL_2=another-channel
EVENT_CHANNEL_3=third-channel
EVENT_CHANNELS="
${EVENT_CHANNEL_1};\Application\Messaging\Impl\HeaderNameFilter|submitted|deleted;\Application\Messaging\Plugin\ExampleTranslator1
${EVENT_CHANNEL_2};\Application\Messaging\Plugin\InvalidFilter;\Application\Messaging\Plugin\ExampleTranslator2
${EVENT_CHANNEL_3}
"
INVALID_CHANNEL=global.invalid
MESSAGE_TOPICS="
${EVENT_CHANNEL_1}:1:1
${EVENT_CHANNEL_2}:1:1
${INVALID_CHANNEL}:1:1
${EVENT_CHANNEL_3}:1:1
"
STORE_DB_USER=adbuser
STORE_DB_PASSWORD=adbpass
STORE_DB_NAME=eventstore
1 change: 1 addition & 0 deletions ops/envs/concurrent/comp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
196 changes: 196 additions & 0 deletions ops/envs/concurrent/comp/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
services:
event-listener-1:
build: ../cont/event-listener
environment:
HOST_GID: ${HOST_UID}
HOST_UID: ${HOST_UID}
HTTP_PORT: ${HTTP_PORT}
TZ: ${TIME_ZONE}
AUTORELOAD_PROGRAMS: "swoole"
AUTORELOAD_ANY_FILES: 0
MESSAGE_BROKER_HOST: kafka-1
MESSAGE_BROKER_PORT: ${MESSAGE_BROKER_PORT}
MESSAGE_CONSUMER_GROUP: ${MESSAGE_CONSUMER_GROUP}
EVENT_CHANNELS: ${EVENT_CHANNELS}
INVALID_CHANNEL: ${INVALID_CHANNEL}
STORE_DB_HOST: db
STORE_DB_USER: ${STORE_DB_USER}
STORE_DB_PASSWORD: ${STORE_DB_PASSWORD}
STORE_DB_NAME: ${STORE_DB_NAME}
expose:
- ${HTTP_PORT}
ports:
- 9501:${HTTP_PORT}
volumes:
- ../../../../dev:/var/www
depends_on:
- kafka-1
- db
event-listener-2:
build: ../cont/event-listener
environment:
HOST_GID: ${HOST_UID}
HOST_UID: ${HOST_UID}
HTTP_PORT: ${HTTP_PORT}
TZ: ${TIME_ZONE}
AUTORELOAD_PROGRAMS: "swoole"
AUTORELOAD_ANY_FILES: 0
MESSAGE_BROKER_HOST: kafka-2
MESSAGE_BROKER_PORT: ${MESSAGE_BROKER_PORT}
MESSAGE_CONSUMER_GROUP: ${MESSAGE_CONSUMER_GROUP}
EVENT_CHANNELS: ${EVENT_CHANNELS}
INVALID_CHANNEL: ${INVALID_CHANNEL}
STORE_DB_HOST: db
STORE_DB_USER: ${STORE_DB_USER}
STORE_DB_PASSWORD: ${STORE_DB_PASSWORD}
STORE_DB_NAME: ${STORE_DB_NAME}
expose:
- ${HTTP_PORT}
ports:
- 9502:${HTTP_PORT}
volumes:
- ../../../../dev:/var/www
depends_on:
- kafka-2
- db
event-listener-3:
build: ../cont/event-listener
environment:
HOST_GID: ${HOST_UID}
HOST_UID: ${HOST_UID}
HTTP_PORT: ${HTTP_PORT}
TZ: ${TIME_ZONE}
AUTORELOAD_PROGRAMS: "swoole"
AUTORELOAD_ANY_FILES: 0
MESSAGE_BROKER_HOST: kafka-3
MESSAGE_BROKER_PORT: ${MESSAGE_BROKER_PORT}
MESSAGE_CONSUMER_GROUP: ${MESSAGE_CONSUMER_GROUP}
EVENT_CHANNELS: ${EVENT_CHANNELS}
INVALID_CHANNEL: ${INVALID_CHANNEL}
STORE_DB_HOST: db
STORE_DB_USER: ${STORE_DB_USER}
STORE_DB_PASSWORD: ${STORE_DB_PASSWORD}
STORE_DB_NAME: ${STORE_DB_NAME}
expose:
- ${HTTP_PORT}
ports:
- 9503:${HTTP_PORT}
volumes:
- ../../../../dev:/var/www
depends_on:
- kafka-3
- db

zookeeper-1:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"sh", "-c",
"/opt/scripts/zookeeper-entrypoint.sh"
]
expose:
- 2181
- 2888
- 3888
environment:
LOG_DIR: /tmp/logs
ZOOKEEPER_ID: 1
ZOOKEEPER_SERVERS: 1=zookeeper-1:2888:3888;2=zookeeper-2:2888:3888;3=zookeeper-3:2888:3888
zookeeper-2:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"sh", "-c",
"/opt/scripts/zookeeper-entrypoint.sh"
]
expose:
- 2181
- 2888
- 3888
environment:
LOG_DIR: /tmp/logs
ZOOKEEPER_ID: 2
ZOOKEEPER_SERVERS: 1=zookeeper-1:2888:3888;2=zookeeper-2:2888:3888;3=zookeeper-3:2888:3888
zookeeper-3:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"sh", "-c",
"/opt/scripts/zookeeper-entrypoint.sh"
]
expose:
- 2181
- 2888
- 3888
environment:
LOG_DIR: /tmp/logs
ZOOKEEPER_ID: 3
ZOOKEEPER_SERVERS: 1=zookeeper-1:2888:3888;2=zookeeper-2:2888:3888;3=zookeeper-3:2888:3888
kafka-1:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"/opt/scripts/entrypoint.sh"
]
depends_on:
- zookeeper-1
expose:
- 9092
- 29092
environment:
LOG_DIR: "/tmp/logs"
KAFKA_BROKER_ID: 1
KAFKA_ADVERTISED_LISTENERS: EXTERNAL://kafka-1:29092,INTERNAL://kafka-1:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
KAFKA_LISTENERS: EXTERNAL://:29092,INTERNAL://:9092
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181
KAFKA_CREATE_TOPICS_SEPARATOR: "$$'\n'"
KAFKA_CREATE_TOPICS: ${MESSAGE_TOPICS}
kafka-2:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"/opt/scripts/entrypoint.sh"
]
depends_on:
- zookeeper-2
expose:
- 9092
- 29092
environment:
LOG_DIR: "/tmp/logs"
KAFKA_BROKER_ID: 2
KAFKA_ADVERTISED_LISTENERS: EXTERNAL://kafka-2:29092,INTERNAL://kafka-2:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
KAFKA_LISTENERS: EXTERNAL://:29092,INTERNAL://:9092
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: zookeeper-2:2181,zookeeper-3:2181,zookeeper-1:2181
KAFKA_CREATE_TOPICS_SEPARATOR: "$$'\n'"
KAFKA_CREATE_TOPICS: ${MESSAGE_TOPICS}
kafka-3:
image: evdobe/kafka:strimzi-0.27.0-kafka-3.0.0-ev2
command: [
"/opt/scripts/entrypoint.sh"
]
depends_on:
- zookeeper-3
expose:
- 9092
- 29092
environment:
LOG_DIR: "/tmp/logs"
KAFKA_BROKER_ID: 3
KAFKA_ADVERTISED_LISTENERS: EXTERNAL://kafka-3:29092,INTERNAL://kafka-3:9092
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: EXTERNAL:PLAINTEXT,INTERNAL:PLAINTEXT
KAFKA_LISTENERS: EXTERNAL://:29092,INTERNAL://:9092
KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL
KAFKA_ZOOKEEPER_CONNECT: zookeeper-3:2181,zookeeper-1:2181,zookeeper-2:2181
KAFKA_CREATE_TOPICS_SEPARATOR: "$$'\n'"
KAFKA_CREATE_TOPICS: ${MESSAGE_TOPICS}

db:
build: ../cont/db/
environment:
POSTGRES_PASSWORD: "${STORE_DB_PASSWORD}"
POSTGRES_USER: "${STORE_DB_USER}"
POSTGRES_DB: "${STORE_DB_NAME}"
POSTGRES_HOST_AUTH_METHOD: trust
expose:
- 5432

4 changes: 4 additions & 0 deletions ops/envs/concurrent/cont/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM postgres:9.6.24
RUN localedef -i el_GR -c -f UTF-8 -A /usr/share/locale/locale.alias el_GR.UTF-8
ENV LANG el_GR.utf8
COPY target /
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@

--
-- PostgreSQL database dump
--

-- Dumped from database version 9.6.24
-- Dumped by pg_dump version 9.6.24

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: event; Type: TABLE; Schema: public; Owner: adbuser
--

CREATE TABLE public.event (
id integer NOT NULL,
"name" text NOT NULL,
channel text NOT NULL,
correlation_id text NOT NULL,
aggregate_id integer NOT NULL,
aggregate_version integer NOT NULL,
data jsonb NOT NULL,
"timestamp" timestamp(3) without time zone DEFAULT now() NOT NULL,
dispatched boolean DEFAULT false NOT NULL,
dispatched_at timestamp(3) without time zone,
received_at timestamp(3) without time zone,
projected boolean DEFAULT false NOT NULL
);


ALTER TABLE public.event OWNER TO adbuser;

--
-- Name: event_id_seq; Type: SEQUENCE; Schema: public; Owner: adbuser
--

CREATE SEQUENCE public.event_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


ALTER TABLE public.event_id_seq OWNER TO adbuser;

--
-- Name: event_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: adbuser
--

ALTER SEQUENCE public.event_id_seq OWNED BY public.event.id;


--
-- Name: event id; Type: DEFAULT; Schema: public; Owner: adbuser
--

ALTER TABLE ONLY public.event ALTER COLUMN id SET DEFAULT nextval('public.event_id_seq'::regclass);


--
-- Name: event event_pkey; Type: CONSTRAINT; Schema: public; Owner: adbuser
--

ALTER TABLE ONLY public.event
ADD CONSTRAINT event_pkey PRIMARY KEY (id);


--
-- PostgreSQL database dump complete
--

Loading

0 comments on commit fff0ac3

Please sign in to comment.