Class: Pgoutput::Client::Runner
- Inherits:
-
Object
- Object
- Pgoutput::Client::Runner
- Defined in:
- lib/pgoutput/client.rb
Overview
High-level logical replication client facade.
‘Runner` is the simplest public entry point for consumers that want to stream raw pgoutput payloads without manually managing a replication connection. It owns the connection lifecycle for one logical replication stream:
-
Build an immutable Configuration from keyword arguments.
-
Open a PostgreSQL replication connection.
-
Optionally create the configured replication slot.
-
Start logical replication.
-
Yield raw pgoutput payload bytes and XLogData metadata.
-
Close the connection when streaming exits.
Instance Attribute Summary collapse
-
#configuration ⇒ Configuration
readonly
Configuration used by this runner.
Instance Method Summary collapse
-
#initialize(**options) ⇒ void
constructor
Build a runner from configuration keyword arguments.
-
#start {|payload, metadata| ... } ⇒ void
Start streaming raw pgoutput payloads.
-
#stop ⇒ void
Request graceful stop.
Constructor Details
#initialize(**options) ⇒ void
Build a runner from configuration keyword arguments.
The accepted keywords are the same as Configuration#initialize. The resulting configuration object is immutable and reused for the lifetime of this runner.
73 74 75 76 77 78 |
# File 'lib/pgoutput/client.rb', line 73 def initialize(**) @configuration = Configuration.new( ** # : untyped ) @stopped = false end |
Instance Attribute Details
#configuration ⇒ Configuration (readonly)
Configuration used by this runner.
61 62 63 |
# File 'lib/pgoutput/client.rb', line 61 def configuration @configuration end |
Instance Method Details
#start {|payload, metadata| ... } ⇒ void
This method returns an undefined value.
Start streaming raw pgoutput payloads.
This method blocks until the stream stops or the underlying connection raises an error. The yielded payload is the raw logical decoding plugin payload contained inside PostgreSQL’s XLogData envelope; callers normally pass this payload to a pgoutput parser.
94 95 96 97 98 99 100 101 102 |
# File 'lib/pgoutput/client.rb', line 94 def start(&block) raise ArgumentError, "block required" unless block connection = Connection.open(configuration) setup_connection(connection) Stream.new(connection:, configuration:).start { |payload, | block.call(payload, ) } ensure connection&.close end |
#stop ⇒ void
This method returns an undefined value.
Request graceful stop.
This method records the caller’s intent to stop. The current implementation does not yet interrupt an active Stream; it exists as part of the public lifecycle API and may be wired into cooperative stream shutdown in a future release.
112 113 114 115 |
# File 'lib/pgoutput/client.rb', line 112 def stop @stopped = true nil end |