Class: OCI::Streaming::StreamClient
- Inherits:
-
Object
- Object
- OCI::Streaming::StreamClient
- Defined in:
- lib/oci/streaming/stream_client.rb
Overview
The API for the Streaming Service.
Instance Attribute Summary collapse
-
#api_client ⇒ OCI::ApiClient
readonly
Client used to make HTTP requests.
-
#endpoint ⇒ String
readonly
Fully qualified endpoint URL.
-
#region ⇒ String
The region, which will usually correspond to a value in Regions::REGION_ENUM.
-
#retry_config ⇒ OCI::Retry::RetryConfig
readonly
The default retry configuration to apply to all operations in this service client.
Instance Method Summary collapse
-
#consumer_commit(stream_id, cursor, opts = {}) ⇒ Response
Provides a mechanism to manually commit offsets, if not using commit-on-get consumer semantics.
-
#consumer_heartbeat(stream_id, cursor, opts = {}) ⇒ Response
Allows long-running processes to extend the timeout on partitions reserved by a consumer instance.
-
#create_cursor(stream_id, create_cursor_details, opts = {}) ⇒ Response
Creates a cursor.
-
#create_group_cursor(stream_id, create_group_cursor_details, opts = {}) ⇒ Response
Creates a group-cursor.
-
#get_group(stream_id, group_name, opts = {}) ⇒ Response
Returns the current state of a consumer group.
-
#get_messages(stream_id, cursor, opts = {}) ⇒ Response
Returns messages from the specified stream using the specified cursor as the starting point for consumption.
-
#initialize(config: nil, region: nil, endpoint: nil, signer: nil, proxy_settings: nil, retry_config: nil) ⇒ StreamClient
constructor
Creates a new StreamClient.
-
#logger ⇒ Logger
The logger for this client.
-
#put_messages(stream_id, put_messages_details, opts = {}) ⇒ Response
Emits messages to a stream.
-
#update_group(stream_id, group_name, update_group_details, opts = {}) ⇒ Response
Forcefully changes the current location of a group as a whole; reseting processing location of all consumers to a particular location in the stream.
Constructor Details
#initialize(config: nil, region: nil, endpoint: nil, signer: nil, proxy_settings: nil, retry_config: nil) ⇒ StreamClient
Creates a new StreamClient. Notes:
If a config is not specified, then the global OCI.config will be used.
This client is not thread-safe
Either a region or an endpoint must be specified. If an endpoint is specified, it will be used instead of the
region. A region may be specified in the config or via or the region parameter. If specified in both, then the
region parameter will be used.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/oci/streaming/stream_client.rb', line 52 def initialize(config: nil, region: nil, endpoint: nil, signer: nil, proxy_settings: nil, retry_config: nil) # If the signer is an InstancePrincipalsSecurityTokenSigner and no config was supplied (which is valid for instance principals) # then create a dummy config to pass to the ApiClient constructor. If customers wish to create a client which uses instance principals # and has config (either populated programmatically or loaded from a file), they must construct that config themselves and then # pass it to this constructor. # # If there is no signer (or the signer is not an instance principals signer) and no config was supplied, this is not valid # so try and load the config from the default file. config ||= OCI.config unless signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) config ||= OCI::Config.new if signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) config.validate unless signer.is_a?(OCI::Auth::Signers::InstancePrincipalsSecurityTokenSigner) if signer.nil? signer = OCI::Signer.new( config.user, config.fingerprint, config.tenancy, config.key_file, pass_phrase: config.pass_phrase, private_key_content: config.key_content ) end @api_client = OCI::ApiClient.new(config, signer, proxy_settings: proxy_settings) @retry_config = retry_config if endpoint @endpoint = endpoint + '/20180418' else region ||= config.region region ||= signer.region if signer.respond_to?(:region) self.region = region end logger.info "StreamClient endpoint set to '#{@endpoint}'." if logger end |
Instance Attribute Details
#api_client ⇒ OCI::ApiClient (readonly)
Client used to make HTTP requests.
12 13 14 |
# File 'lib/oci/streaming/stream_client.rb', line 12 def api_client @api_client end |
#endpoint ⇒ String (readonly)
Fully qualified endpoint URL
16 17 18 |
# File 'lib/oci/streaming/stream_client.rb', line 16 def endpoint @endpoint end |
#region ⇒ String
The region, which will usually correspond to a value in Regions::REGION_ENUM.
26 27 28 |
# File 'lib/oci/streaming/stream_client.rb', line 26 def region @region end |
#retry_config ⇒ OCI::Retry::RetryConfig (readonly)
The default retry configuration to apply to all operations in this service client. This can be overridden on a per-operation basis. The default retry configuration value is ‘nil`, which means that an operation will not perform any retries
22 23 24 |
# File 'lib/oci/streaming/stream_client.rb', line 22 def retry_config @retry_config end |
Instance Method Details
#consumer_commit(stream_id, cursor, opts = {}) ⇒ Response
Provides a mechanism to manually commit offsets, if not using commit-on-get consumer semantics. This commits offsets assicated with the provided cursor, extends the timeout on each of the affected partitions, and returns an updated cursor.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/oci/streaming/stream_client.rb', line 124 def consumer_commit(stream_id, cursor, opts = {}) logger.debug 'Calling operation StreamClient#consumer_commit.' if logger raise "Missing the required parameter 'stream_id' when calling consumer_commit." if stream_id.nil? raise "Missing the required parameter 'cursor' when calling consumer_commit." if cursor.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/commit'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} query_params[:cursor] = cursor # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = nil # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#consumer_commit') do @api_client.call_api( :POST, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::Cursor' ) end # rubocop:enable Metrics/BlockLength end |
#consumer_heartbeat(stream_id, cursor, opts = {}) ⇒ Response
Allows long-running processes to extend the timeout on partitions reserved by a consumer instance.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/oci/streaming/stream_client.rb', line 184 def consumer_heartbeat(stream_id, cursor, opts = {}) logger.debug 'Calling operation StreamClient#consumer_heartbeat.' if logger raise "Missing the required parameter 'stream_id' when calling consumer_heartbeat." if stream_id.nil? raise "Missing the required parameter 'cursor' when calling consumer_heartbeat." if cursor.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/heartbeat'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} query_params[:cursor] = cursor # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = nil # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#consumer_heartbeat') do @api_client.call_api( :POST, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::Cursor' ) end # rubocop:enable Metrics/BlockLength end |
#create_cursor(stream_id, create_cursor_details, opts = {}) ⇒ Response
Creates a cursor. Cursors are used to consume a stream, starting from a specific point in the partition and going forward from there. You can create a cursor based on an offset, a time, the trim horizon, or the most recent message in the stream. As the oldest message inside the retention period boundary, using the trim horizon effectively lets you consume all messages in the stream. A cursor based on the most recent message allows consumption of only messages that are added to the stream after you create the cursor. Cursors expire five minutes after you receive them from the service.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/oci/streaming/stream_client.rb', line 247 def create_cursor(stream_id, create_cursor_details, opts = {}) logger.debug 'Calling operation StreamClient#create_cursor.' if logger raise "Missing the required parameter 'stream_id' when calling create_cursor." if stream_id.nil? raise "Missing the required parameter 'create_cursor_details' when calling create_cursor." if create_cursor_details.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/cursors'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = @api_client.object_to_http_body(create_cursor_details) # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#create_cursor') do @api_client.call_api( :POST, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::Cursor' ) end # rubocop:enable Metrics/BlockLength end |
#create_group_cursor(stream_id, create_group_cursor_details, opts = {}) ⇒ Response
Creates a group-cursor.
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/oci/streaming/stream_client.rb', line 305 def create_group_cursor(stream_id, create_group_cursor_details, opts = {}) logger.debug 'Calling operation StreamClient#create_group_cursor.' if logger raise "Missing the required parameter 'stream_id' when calling create_group_cursor." if stream_id.nil? raise "Missing the required parameter 'create_group_cursor_details' when calling create_group_cursor." if create_group_cursor_details.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/groupCursors'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = @api_client.object_to_http_body(create_group_cursor_details) # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#create_group_cursor') do @api_client.call_api( :POST, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::Cursor' ) end # rubocop:enable Metrics/BlockLength end |
#get_group(stream_id, group_name, opts = {}) ⇒ Response
Returns the current state of a consumer group.
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
# File 'lib/oci/streaming/stream_client.rb', line 363 def get_group(stream_id, group_name, opts = {}) logger.debug 'Calling operation StreamClient#get_group.' if logger raise "Missing the required parameter 'stream_id' when calling get_group." if stream_id.nil? raise "Missing the required parameter 'group_name' when calling get_group." if group_name.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) raise "Parameter value for 'group_name' must not be blank" if OCI::Internal::Util.blank_string?(group_name) path = '/streams/{streamId}/groups/{groupName}'.sub('{streamId}', stream_id.to_s).sub('{groupName}', group_name.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = nil # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#get_group') do @api_client.call_api( :GET, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::Group' ) end # rubocop:enable Metrics/BlockLength end |
#get_messages(stream_id, cursor, opts = {}) ⇒ Response
Returns messages from the specified stream using the specified cursor as the starting point for consumption. By default, the number of messages returned is undefined, but the service returns as many as possible. To get messages, you must first obtain a cursor using the create_cursor operation. In the response, retrieve the value of the ‘opc-next-cursor’ header to pass as a parameter to get the next batch of messages in the stream.
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 |
# File 'lib/oci/streaming/stream_client.rb', line 428 def (stream_id, cursor, opts = {}) logger.debug 'Calling operation StreamClient#get_messages.' if logger raise "Missing the required parameter 'stream_id' when calling get_messages." if stream_id.nil? raise "Missing the required parameter 'cursor' when calling get_messages." if cursor.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/messages'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} query_params[:cursor] = cursor query_params[:limit] = opts[:limit] if opts[:limit] # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = nil # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#get_messages') do @api_client.call_api( :GET, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'Array<OCI::Streaming::Models::Message>' ) end # rubocop:enable Metrics/BlockLength end |
#logger ⇒ Logger
Returns The logger for this client. May be nil.
102 103 104 |
# File 'lib/oci/streaming/stream_client.rb', line 102 def logger @api_client.config.logger end |
#put_messages(stream_id, put_messages_details, opts = {}) ⇒ Response
Emits messages to a stream. There’s no limit to the number of messages in a request, but the total size of a message or request must be 1 MiB or less. The service calculates the partition ID from the message key and stores messages that share a key on the same partition. If a message does not contain a key or if the key is null, the service generates a message key for you. The partition ID cannot be passed as a parameter.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/oci/streaming/stream_client.rb', line 491 def (stream_id, , opts = {}) logger.debug 'Calling operation StreamClient#put_messages.' if logger raise "Missing the required parameter 'stream_id' when calling put_messages." if stream_id.nil? raise "Missing the required parameter 'put_messages_details' when calling put_messages." if .nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) path = '/streams/{streamId}/messages'.sub('{streamId}', stream_id.to_s) operation_signing_strategy = :exclude_body # rubocop:disable Style/NegatedIf # Query Params query_params = {} # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = @api_client.object_to_http_body() # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#put_messages') do @api_client.call_api( :POST, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body, return_type: 'OCI::Streaming::Models::PutMessagesResult' ) end # rubocop:enable Metrics/BlockLength end |
#update_group(stream_id, group_name, update_group_details, opts = {}) ⇒ Response
Forcefully changes the current location of a group as a whole; reseting processing location of all consumers to a particular location in the stream.
550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/oci/streaming/stream_client.rb', line 550 def update_group(stream_id, group_name, update_group_details, opts = {}) logger.debug 'Calling operation StreamClient#update_group.' if logger raise "Missing the required parameter 'stream_id' when calling update_group." if stream_id.nil? raise "Missing the required parameter 'group_name' when calling update_group." if group_name.nil? raise "Missing the required parameter 'update_group_details' when calling update_group." if update_group_details.nil? raise "Parameter value for 'stream_id' must not be blank" if OCI::Internal::Util.blank_string?(stream_id) raise "Parameter value for 'group_name' must not be blank" if OCI::Internal::Util.blank_string?(group_name) path = '/streams/{streamId}/groups/{groupName}'.sub('{streamId}', stream_id.to_s).sub('{groupName}', group_name.to_s) operation_signing_strategy = :standard # rubocop:disable Style/NegatedIf # Query Params query_params = {} # Header Params header_params = {} header_params[:accept] = 'application/json' header_params[:'content-type'] = 'application/json' header_params[:'opc-request-id'] = opts[:opc_request_id] if opts[:opc_request_id] # rubocop:enable Style/NegatedIf post_body = @api_client.object_to_http_body(update_group_details) # rubocop:disable Metrics/BlockLength OCI::Retry.(applicable_retry_config(opts), call_name: 'StreamClient#update_group') do @api_client.call_api( :PUT, path, endpoint, header_params: header_params, query_params: query_params, operation_signing_strategy: operation_signing_strategy, body: post_body ) end # rubocop:enable Metrics/BlockLength end |