{"id":482614,"date":"2026-06-06T08:39:40","date_gmt":"2026-06-06T08:39:40","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=482614"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=482614","title":{"rendered":"Muxalma \u2014 \u043e\u0431\u043c\u0435\u043d \u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0449\u0435\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p><a href=\"https:\/\/github.com\/alamar\/muxalma\" rel=\"noopener noreferrer nofollow\">\u041f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub<\/a> \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u043d\u043d\u0435\u0439 \u0430\u043b\u044c\u0444\u044b. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442 README \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<p>\u0421\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0432\u043a\u0443\u0441\u0443. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code>public interface NetworkEvent {    UUID getConnectionId();    int getSerial();    EventType getType();    byte[] getPayload();}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041e\u043d\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0442\u0435\u0432\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 (\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u043b\u043e\u0441\u044c, \u043f\u0440\u0438\u0448\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u043b\u043e\u0441\u044c \u0438\u043b\u0438 \u043e\u0431\u043e\u0440\u0432\u0430\u043d\u043e) \u0438 \u043f\u043e\u0434\u0434\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 <code>Consumer&lt;NetworkEvent&gt;<\/code>, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438 \u043b\u0430\u0431\u0438\u0440\u0438\u043d\u0442\u044b \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438, \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430, \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0442.\u043f.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0443\u043c\u0435\u044e\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b &#8212; \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u043b\u0430\u0436\u0435\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043f\u0440\u0438 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u044f\u043c\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 &#8212; HTTP-\u043f\u0440\u043e\u043a\u0441\u0438. \u041e\u0434\u0438\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 &#8212; \u043f\u0440\u0438\u0451\u043c\u043d\u0438\u043a \u043f\u0440\u043e\u043a\u0441\u0438, &#171;\u043c\u0430\u043c\u0430&#187;, \u0442\u043e, \u0447\u0442\u043e \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 3128 \u043e\u0431\u044b\u0447\u043d\u043e. \u041e\u043d \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0442\u0443\u0442 \u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b &#8212; \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0432\u0438\u0434\u0435 <code>NetworkEvent<\/code> \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0410 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u043a\u0441\u0438, &#171;\u043f\u0430\u043f\u0430&#187;, \u0443\u0436\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0432\u043e\u0451\u043c \u0441\u0435\u0442\u0435\u0432\u043e\u043c \u0441\u0442\u0435\u043a\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 <code>NetworkEvent<\/code> \u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 &#171;\u043c\u0430\u043c\u0435&#187;.<\/p>\n<p>\u0412\u0441\u044f \u0441\u0443\u0442\u044c \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442 (\u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430) \u043f\u0438\u0448\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u0441\u0438\u044e\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u043d\u0443\u0436\u0434\u044b. \u042f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 H2SQL \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0427\u0442\u0435\u043d\u0438\u0435:<\/p>\n<pre><code>public class H2Retrieval extends PollingRetrievalSupport {    private final String connectionUrl;    private final String tableName;    private final Consumer&lt;NetworkEvent&gt; targetConsumer;    private final AtomicLong lastProcessedId = new AtomicLong();    public H2Retrieval(String databasePath, String tableName, Consumer&lt;NetworkEvent&gt; targetConsumer, long pollIntervalMs) {        super(pollIntervalMs);        this.connectionUrl = String.format(                \"jdbc:h2:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000\",                Paths.get(databasePath).toAbsolutePath()        );        this.tableName = tableName;        this.targetConsumer = targetConsumer;    }    protected void poll() {        String selectSQL = String.format(\"\"\"                SELECT id, connection_id, serial, event_type, payload                 FROM %s                 WHERE id &gt; ?                 ORDER BY id ASC                \"\"\", tableName);        try (Connection conn = DriverManager.getConnection(connectionUrl);             PreparedStatement pstmt = conn.prepareStatement(selectSQL)) {            pstmt.setLong(1, lastProcessedId.get());            long eventId = lastProcessedId.get();            try (ResultSet rs = pstmt.executeQuery()) {                while (rs.next()) {                    eventId = rs.getLong(\"id\");                    NetworkEvent event = extractEvent(rs);                    targetConsumer.accept(event);                }            } finally {                long finalEventId = eventId;                lastProcessedId.updateAndGet(val -&gt; Math.max(val, finalEventId));            }        } catch (SQLException e) {            throw new RuntimeException(\"Failed to poll events\", e);        }    }    private NetworkEvent extractEvent(ResultSet rs) throws SQLException {        UUID connectionId = (UUID) rs.getObject(\"connection_id\");        int serial = rs.getInt(\"serial\");        EventType type = EventType.valueOf(rs.getString(\"event_type\"));        byte[] payload = rs.getBytes(\"payload\");        return NetworkEvent.create(connectionId, serial, type, payload);    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418 \u0437\u0430\u043f\u0438\u0441\u044c:<\/p>\n<pre><code>public class H2Storage implements Consumer&lt;NetworkEvent&gt; {    private final String connectionUrl;    private final String tableName;    public H2Storage(String databasePath, String tableName) {        this.connectionUrl = String.format(                \"jdbc:h2:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000\",                Paths.get(databasePath).toAbsolutePath()        );        this.tableName = tableName;    }    @Override    public void accept(NetworkEvent event) {        String insertSQL = String.format(\"\"\"            INSERT INTO %s (connection_id, serial, event_type, payload)             VALUES (?, ?, ?, ?)            \"\"\", tableName);        try (Connection conn = DriverManager.getConnection(connectionUrl);             PreparedStatement pstmt = conn.prepareStatement(insertSQL)) {            pstmt.setObject(1, event.getConnectionId());            pstmt.setInt(2, event.getSerial());            pstmt.setString(3, event.getType().name());            pstmt.setBytes(4, event.getPayload());            pstmt.executeUpdate();        } catch (SQLException e) {            throw new RuntimeException(\"Failed to store network event\", e);        }    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c, \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u0432\u0441\u0451. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0449\u0435, \u0435\u0441\u043b\u0438 Muxalma \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0438\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u0443\u043c\u043d\u0435\u0435 &#8212; \u043d\u0430\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u0440\u044e \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0448\u0435\u0439\u043f\u0438\u043d\u0433\u0443 \u0442\u0440\u0430\u0444\u0438\u043a\u0430, backpressure \u0438 \u0442.\u043f. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Netty \u0447\u0435\u0440\u0435\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u0432\u0430\u043c\u0438. \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u0443\u0434\u044c\u0431\u044b HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u043a\u0441 \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u041c\u0443\u043a\u0441\u0430\u043b\u043c\u0430.<\/p>\n<p>\u0418 \u0437\u0434\u0435\u0441\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c &#8212; \u0433\u043e\u0441\u043f\u043e\u0434\u0438\u043d \u0445\u043e\u0440\u043e\u0448\u0438\u0439, <strong>\u043d\u0435 \u043b\u043e\u043c\u0438\u0442\u0435\u0441\u044c \u043b\u0438 \u0432\u044b \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u0443\u044e \u0434\u0432\u0435\u0440\u044c<\/strong> \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u043e\u0434\u0435\u043b\u043a\u043e\u0439 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0441 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u0432? \u041d\u0430 \u044d\u0442\u043e \u044f \u043e\u0442\u0432\u0435\u0447\u0443, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044e, \u0442.\u043a. \u0434\u0432\u0435\u0440\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0445\u043e\u0434\u0443 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b, \u0430 \u0435\u0449\u0451 \u044f \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u0430 \u043d\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c, \u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u0432 \u0443\u0437\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445 \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0443.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1044330\/\">https:\/\/habr.com\/ru\/articles\/1044330\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430 GitHub \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u043d\u043d\u0435\u0439 \u0430\u043b\u044c\u0444\u044b. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0435\u0442 README \u043f\u0440\u043e\u0435\u043a\u0442\u0430.\u0421\u0435\u0442\u0435\u0432\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0432\u043a\u0443\u0441\u0443. \u041a\u0430\u0436\u0434\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:public interface NetworkEvent {    UUID getConnectionId();    int getSerial();    EventType getType();    byte[] getPayload();}\u041e\u043d\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u0435\u0442\u0435\u0432\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 (\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043a\u0440\u044b\u043b\u043e\u0441\u044c, \u043f\u0440\u0438\u0448\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0437\u0430\u043a\u0440\u044b\u043b\u043e\u0441\u044c \u0438\u043b\u0438 \u043e\u0431\u043e\u0440\u0432\u0430\u043d\u043e) \u0438 \u043f\u043e\u0434\u0434\u0430\u044e\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0447\u0435\u0440\u0435\u0437 Consumer&lt;NetworkEvent&gt;, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438 \u043b\u0430\u0431\u0438\u0440\u0438\u043d\u0442\u044b \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438, \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430, \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0432\u0430\u043d\u0438\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0442.\u043f.\u0415\u0441\u043b\u0438 \u0434\u0432\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0443\u043c\u0435\u044e\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b &#8212; \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u043d\u0430\u043b\u0430\u0436\u0435\u043d\u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u043f\u0440\u0438 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u044f\u043c\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0434\u0440\u0443\u0433 \u043a \u0434\u0440\u0443\u0433\u0443 \u043e\u043d\u0438 \u043d\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u044f\u0442.\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430 &#8212; HTTP-\u043f\u0440\u043e\u043a\u0441\u0438. \u041e\u0434\u0438\u043d \u043f\u0440\u043e\u0446\u0435\u0441\u0441 &#8212; \u043f\u0440\u0438\u0451\u043c\u043d\u0438\u043a \u043f\u0440\u043e\u043a\u0441\u0438, &#171;\u043c\u0430\u043c\u0430&#187;, \u0442\u043e, \u0447\u0442\u043e \u0441\u043b\u0443\u0448\u0430\u0435\u0442 \u043d\u0430 \u043f\u043e\u0440\u0442\u0443 3128 \u043e\u0431\u044b\u0447\u043d\u043e. \u041e\u043d \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u043a\u0441\u0438 \u0442\u0443\u0442 \u0436\u0435 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b &#8212; \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432 \u0432\u0438\u0434\u0435 NetworkEvent \u0438 \u043a\u043b\u0430\u0434\u0451\u0442 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435. \u0410 \u0432 \u044d\u0442\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043e\u0432\u0441\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a \u043f\u0440\u043e\u043a\u0441\u0438, &#171;\u043f\u0430\u043f\u0430&#187;, \u0443\u0436\u0435 \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0430 \u0441\u0432\u043e\u0451\u043c \u0441\u0435\u0442\u0435\u0432\u043e\u043c \u0441\u0442\u0435\u043a\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442\u044b \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0438\u0445 \u0447\u0435\u0440\u0435\u0437 NetworkEvent \u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 &#171;\u043c\u0430\u043c\u0435&#187;.\u0412\u0441\u044f \u0441\u0443\u0442\u044c \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442 (\u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430) \u043f\u0438\u0448\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u0441\u0438\u044e\u043c\u0438\u043d\u0443\u0442\u043d\u044b\u0435 \u043d\u0443\u0436\u0434\u044b. \u042f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 H2SQL \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0427\u0442\u0435\u043d\u0438\u0435:public class H2Retrieval extends PollingRetrievalSupport {    private final String connectionUrl;    private final String tableName;    private final Consumer&lt;NetworkEvent&gt; targetConsumer;    private final AtomicLong lastProcessedId = new AtomicLong();    public H2Retrieval(String databasePath, String tableName, Consumer&lt;NetworkEvent&gt; targetConsumer, long pollIntervalMs) {        super(pollIntervalMs);        this.connectionUrl = String.format(                &#171;jdbc:h2:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000&#187;,                Paths.get(databasePath).toAbsolutePath()        );        this.tableName = tableName;        this.targetConsumer = targetConsumer;    }    protected void poll() {        String selectSQL = String.format(&#171;&#187;&#187;                SELECT id, connection_id, serial, event_type, payload                 FROM %s                 WHERE id &gt; ?                 ORDER BY id ASC                &#171;&#187;&#187;, tableName);        try (Connection conn = DriverManager.getConnection(connectionUrl);             PreparedStatement pstmt = conn.prepareStatement(selectSQL)) {            pstmt.setLong(1, lastProcessedId.get());            long eventId = lastProcessedId.get();            try (ResultSet rs = pstmt.executeQuery()) {                while (rs.next()) {                    eventId = rs.getLong(&#171;id&#187;);                    NetworkEvent event = extractEvent(rs);                    targetConsumer.accept(event);                }            } finally {                long finalEventId = eventId;                lastProcessedId.updateAndGet(val -&gt; Math.max(val, finalEventId));            }        } catch (SQLException e) {            throw new RuntimeException(&#171;Failed to poll events&#187;, e);        }    }    private NetworkEvent extractEvent(ResultSet rs) throws SQLException {        UUID connectionId = (UUID) rs.getObject(&#171;connection_id&#187;);        int serial = rs.getInt(&#171;serial&#187;);        EventType type = EventType.valueOf(rs.getString(&#171;event_type&#187;));        byte[] payload = rs.getBytes(&#171;payload&#187;);        return NetworkEvent.create(connectionId, serial, type, payload);    }}\u0418 \u0437\u0430\u043f\u0438\u0441\u044c:public class H2Storage implements Consumer&lt;NetworkEvent&gt; {    private final String connectionUrl;    private final String tableName;    public H2Storage(String databasePath, String tableName) {        this.connectionUrl = String.format(                &#171;jdbc:h2:%s;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=10000&#187;,                Paths.get(databasePath).toAbsolutePath()        );        this.tableName = tableName;    }    @Override    public void accept(NetworkEvent event) {        String insertSQL = String.format(&#171;&#187;&#187;            INSERT INTO %s (connection_id, serial, event_type, payload)             VALUES (?, ?, ?, ?)            &#171;&#187;&#187;, tableName);        try (Connection conn = DriverManager.getConnection(connectionUrl);             PreparedStatement pstmt = conn.prepareStatement(insertSQL)) {            pstmt.setObject(1, event.getConnectionId());            pstmt.setInt(2, event.getSerial());            pstmt.setString(3, event.getType().name());            pstmt.setBytes(4, event.getPayload());            pstmt.executeUpdate();        } catch (SQLException e) {            throw new RuntimeException(&#171;Failed to store network event&#187;, e);        }    }}\u041d\u0430 \u044d\u0442\u043e\u043c, \u0432 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e, \u0432\u0441\u0451. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041e\u043d \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0434\u0430\u0436\u0435 \u043f\u0440\u043e\u0449\u0435, \u0435\u0441\u043b\u0438 Muxalma \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0441\u0432\u043e\u0438\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0441\u0442\u0430\u043d\u0435\u0442 \u0443\u043c\u043d\u0435\u0435 &#8212; \u043d\u0430\u0443\u0447\u0438\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0435\u043d\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u0440\u044e \u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u0448\u0435\u0439\u043f\u0438\u043d\u0433\u0443 \u0442\u0440\u0430\u0444\u0438\u043a\u0430, backpressure \u0438 \u0442.\u043f. \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b HTTP-\u043f\u0440\u043e\u043a\u0441\u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Netty \u0447\u0435\u0440\u0435\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437\u0431\u0440\u0430\u043d\u043d\u043e\u0435 \u0432\u0430\u043c\u0438. \u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0441\u0443\u0434\u044c\u0431\u044b HTTP-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0438 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u043b\u0435\u043a\u0441 \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u041c\u0443\u043a\u0441\u0430\u043b\u043c\u0430.\u0418 \u0437\u0434\u0435\u0441\u044c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043a\u0430\u0437\u0430\u0442\u044c &#8212; \u0433\u043e\u0441\u043f\u043e\u0434\u0438\u043d \u0445\u043e\u0440\u043e\u0448\u0438\u0439, \u043d\u0435 \u043b\u043e\u043c\u0438\u0442\u0435\u0441\u044c \u043b\u0438 \u0432\u044b \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u0443\u044e \u0434\u0432\u0435\u0440\u044c \u0441\u043e \u0441\u0432\u043e\u0435\u0439 \u043f\u043e\u0434\u0435\u043b\u043a\u043e\u0439 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0441 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u043e\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u0432? \u041d\u0430 \u044d\u0442\u043e \u044f \u043e\u0442\u0432\u0435\u0447\u0443, \u0447\u0442\u043e \u0445\u043e\u0442\u0435\u043b \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u0443 \u0434\u0438\u0441\u043a\u0443\u0441\u0441\u0438\u044e, \u0442.\u043a. \u0434\u0432\u0435\u0440\u044c \u0442\u0430\u043a\u0443\u044e \u0441\u0445\u043e\u0434\u0443 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b, \u0430 \u0435\u0449\u0451 \u044f \u043f\u0438\u0441\u0430\u0442\u0435\u043b\u044c, \u0430 \u043d\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c, \u0438 \u0448\u0438\u0440\u043e\u043a\u043e \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0435 \u0432 \u0443\u0437\u043a\u0438\u0445 \u043a\u0440\u0443\u0433\u0430\u0445 \u0432\u0441\u0435\u043c\u0438 \u043f\u0440\u0438\u0437\u043d\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u043d\u0430\u0439\u0434\u0443.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1044330\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-482614","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/482614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=482614"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/482614\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=482614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=482614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=482614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}