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
Copy file name to clipboardExpand all lines: README.md
+16-6Lines changed: 16 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,8 +36,10 @@ CREATE TABLE consumer (
36
36
topic TEXTNOT NULL,
37
37
name TEXTNOT NULL,
38
38
partition SMALLINTNOT NULL,
39
+
first_event_id BIGINT,
39
40
last_event_id BIGINT,
40
41
last_consumption_at TIMESTAMP,
42
+
consumed_events BIGINTNOT NULL,
41
43
created_at TIMESTAMPNOT NULL DEFAULT NOW(),
42
44
PRIMARY KEY (topic, name, partition)
43
45
);
@@ -54,6 +56,9 @@ FOR UPDATE SKIP LOCKED;
54
56
55
57
SELECT*FROM event
56
58
WHERE topic = :topic AND (:last_event_id IS NULLOR id > :last_event_id)
59
+
-- eventual consistency of auto increment; there is no guarantee that record of id 2 is visible after id 1 record --
60
+
-- in the implementation, we set insert statements timeout to '250 ms' so it is safe --
61
+
AND created_at < (NOW() - interval '333 ms')
57
62
ORDER BY id LIMIT :limit;
58
63
59
64
(process events)
@@ -82,6 +87,9 @@ FOR UPDATE SKIP LOCKED;
82
87
83
88
SELECT*FROM event
84
89
WHERE topic = :topic AND partition =0AND (:last_event_id IS NULLOR id > :last_event_id)
90
+
-- eventual consistency of auto increment; there is no guarantee that record of id 2 is visible after id 1 record --
91
+
-- in the implementation, we set insert statements timeout to '250 ms' so it is safe --
92
+
AND created_at < (NOW() - interval '333 ms')
85
93
ORDER BY id LIMIT :limit;
86
94
87
95
(process events)
@@ -99,18 +107,20 @@ definition has. It's a rather acceptable tradeoff and easy to enforce at the lib
99
107
100
108
## How to use it
101
109
102
-
`EventSQL` is an entrypoint to the whole library. It requires standard Java `javax.sql.DataSource` or a list of
110
+
`EventSQL` is an entrypoint to the whole library. It requires single data source properties or a list of
103
111
them:
104
112
105
113
```java
106
-
107
114
importcom.binaryigor.eventsql.EventSQL;
108
-
importjavax.sql.DataSource;
109
-
// dialect of your events backend - POSTGRES, MYSQL, MARIADB and so on;
115
+
// EventSQL.Dialect is a dialect of your events backend - POSTGRES, MYSQL, MARIADB and so on;
110
116
// as of now, only POSTGRES has fully tested support;
111
117
// 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
112
-
var eventSQL =newEventSQL(dataSource, EventSQLDialect.POSTGRES);
113
-
ver shardedEventSQL =newEventSQL(dataSources, EventSQLDialect.POSTGRES);
118
+
var eventSQL =EventSQL.of(newEventSQL.DataSourceProperties(EventSQL.Dialect.POSTGRES, "dbUrl", "dbUsername", "dbPassword"));
* Primary constructor used mainly for internal purposes.
53
+
* It should rarely be used outside library implementation, only if static of factories do not provide what is necessary.
54
+
* Additionally, if used, PUBLISH_TIMEOUT must be set as a query/statement timeout on each newly open data source connection.
55
+
* If not, there is a risk of loosing some events by consumers - it is being set by static of methods when dataSource() factory is called; check them out for guidance.
56
+
*
57
+
* @param dataSources list of data sources where events are hosted
58
+
* @param clock clock used mainly for consumer delays
0 commit comments