You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
--Used to lock single (per topic) event_buffer to {topic}_event writer --
65
63
CREATETABLEevent_buffer_lock (
66
-
created_at TIMESTAMPNOT NULL DEFAULT NOW()
64
+
topic TEXTPRIMARY KEY
67
65
);
68
-
INSERT INTO event_buffer_lock VALUES (DEFAULT);
69
66
```
70
67
71
-
To consume messages, we just need to periodically (every one to a few seconds) do:
68
+
To consume events, we just need to periodically (every one to a few seconds) do:
72
69
73
70
```sql
74
71
BEGIN;
@@ -77,8 +74,8 @@ SELECT * FROM consumer
77
74
WHERE topic = :topic AND name = :c_name
78
75
FOR UPDATE SKIP LOCKED;
79
76
80
-
SELECT*FROMevent
81
-
WHEREtopic = :topic AND(:last_event_id IS NULLOR id > :last_event_id)
77
+
SELECT*FROM{topic}_event
78
+
WHERE (:last_event_id IS NULLOR id > :last_event_id)
82
79
ORDER BY id LIMIT :limit;
83
80
84
81
(process events)
@@ -105,8 +102,8 @@ SELECT * FROM consumer
105
102
WHERE topic = :topic AND name = :c_name AND partition =0
106
103
FOR UPDATE SKIP LOCKED;
107
104
108
-
SELECT*FROMevent
109
-
WHEREtopic = :topic ANDpartition =0AND (:last_event_id IS NULLOR id > :last_event_id)
105
+
SELECT*FROM{topic}_event
106
+
WHERE partition =0AND (:last_event_id IS NULLOR id > :last_event_id)
110
107
ORDER BY id LIMIT :limit;
111
108
112
109
(process events)
@@ -130,9 +127,8 @@ them:
130
127
```java
131
128
132
129
importcom.binaryigor.eventsql.EventSQL;
133
-
// dialect of your events backend - POSTGRES, MYSQL, MARIADB and so on;
134
-
// as of now, only POSTGRES has fully tested support;
135
-
// should also work with others but some things - event table partition management for example - works only with Postgres, for others it must be managed manually
130
+
// dialect of your events backend - POSTGRES, MYSQL, MARIADB;
131
+
// as of now, only POSTGRES has fully tested support, but should work on others as well
136
132
importcom.binaryigor.eventsql.EventSQLDialect;
137
133
importjavax.sql.DataSource;
138
134
@@ -142,6 +138,9 @@ ver shardedEventSQL = new EventSQL(dataSources, EventSQLDialect.POSTGRES);
142
138
143
139
Sharded version works in the same vain - it just assumes that topics and consumers are hosted on multiple dbs.
144
140
141
+
Required tables are managed automatically by the library, but if you want to customize their schema a bit, you can provide your own `EventSQLRegistry.TablesManager` implementation.
142
+
See `EventSQLRegistry` for details.
143
+
145
144
### Topics and Consumers
146
145
147
146
Having `EventSQL` instance, we can register topics and their consumers:
@@ -248,7 +247,7 @@ var consumers = eventSQL.consumers();
0 commit comments