PubsubGrpc.Client (PubsubGrpc v0.4.2)

View Source

Client module for interacting with Google Cloud Pub/Sub using gRPC connections.

This module provides a wrapper around GrpcConnectionPool that automatically uses the default connection pool configured for Pub/Sub.

For most use cases, use the main PubsubGrpc module instead, as it provides a higher-level API for common operations.

Examples

operation = fn channel ->
  request = %Google.Pubsub.V1.GetTopicRequest{topic: "projects/my-project/topics/my-topic"}
  Google.Pubsub.V1.Publisher.Stub.get_topic(channel, request, [])
end

{:ok, {:ok, topic}} = PubsubGrpc.Client.execute(operation)

Summary

Functions

Execute a gRPC operation using a connection from the pool.

Gets the status of the connection pool.

Execute a function with a connection from the pool.

Functions

execute(operation_fn, opts \\ [])

@spec execute(
  (GRPC.Channel.t() -> term()),
  keyword()
) :: {:ok, term()} | {:error, term()}

Execute a gRPC operation using a connection from the pool.

Parameters

  • operation_fn: A 1-arity function that receives a gRPC channel and returns a result
  • opts: Optional parameters
    • :pool - Pool name to use (default: PubsubGrpc.ConnectionPool)

Returns

  • {:ok, result} - Result from the operation function
  • {:error, reason} - Error during connection checkout

Examples

operation = fn channel ->
  request = %Google.Pubsub.V1.Topic{name: "projects/my-project/topics/test"}
  Google.Pubsub.V1.Publisher.Stub.create_topic(channel, request, [])
end

{:ok, {:ok, topic}} = PubsubGrpc.Client.execute(operation)

status(opts \\ [])

@spec status(keyword()) :: map()

Gets the status of the connection pool.

Parameters

  • opts: Optional parameters
    • :pool - Pool name to check (default: PubsubGrpc.ConnectionPool)

Returns

  • Pool status map with worker counts and statistics

with_connection(fun, opts \\ [])

@spec with_connection(
  (GRPC.Channel.t() -> term()),
  keyword()
) :: {:ok, term()} | {:error, term()}

Execute a function with a connection from the pool.

Alias for execute/2.