diff --git a/metadata/V1/Publisher.php b/metadata/V1/Publisher.php
index 8c3d1fb..0038c4e 100644
--- a/metadata/V1/Publisher.php
+++ b/metadata/V1/Publisher.php
@@ -15,18 +15,23 @@ public static function initOnce() {
return;
}
\GPBMetadata\Google\Api\Annotations::initOnce();
- \GPBMetadata\Google\Protobuf\Any::initOnce();
\GPBMetadata\Google\Api\Client::initOnce();
+ \GPBMetadata\Google\Protobuf\Any::initOnce();
$pool->internalAddGeneratedFile(
'
-
-3google/cloud/eventarc/publishing/v1/publisher.proto#google.cloud.eventarc.publishing.v1google/protobuf/any.protogoogle/api/client.proto"i
+è
+3google/cloud/eventarc/publishing/v1/publisher.proto#google.cloud.eventarc.publishing.v1google/api/client.protogoogle/protobuf/any.proto"i
%PublishChannelConnectionEventsRequest
channel_connection ( $
events (2.google.protobuf.Any"(
-&PublishChannelConnectionEventsResponse2ý
+&PublishChannelConnectionEventsResponse"M
+PublishEventsRequest
+channel ( $
+events (2.google.protobuf.Any"
+PublishEventsResponse2Ð
Publisher˜
-PublishChannelConnectionEventsJ.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsRequestK.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsResponse"]‚Óä“W"R/v1/{channel_connection=projects/*/locations/*/channelConnections/*}:publishEvents:*UÊA!eventarcpublishing.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÿ
+PublishChannelConnectionEventsJ.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsRequestK.google.cloud.eventarc.publishing.v1.PublishChannelConnectionEventsResponse"]‚Óä“W"R/v1/{channel_connection=projects/*/locations/*/channelConnections/*}:publishEvents:*Ð
+
PublishEvents9.google.cloud.eventarc.publishing.v1.PublishEventsRequest:.google.cloud.eventarc.publishing.v1.PublishEventsResponse"H‚Óä“B"=/v1/{channel=projects/*/locations/*/channels/*}:publishEvents:*UÊA!eventarcpublishing.googleapis.comÒA.https://www.googleapis.com/auth/cloud-platformBÿ
\'com.google.cloud.eventarc.publishing.v1BPublisherProtoPZLgoogle.golang.org/genproto/googleapis/cloud/eventarc/publishing/v1;publisherª#Google.Cloud.Eventarc.Publishing.V1Ê#Google\\Cloud\\Eventarc\\Publishing\\V1ê\'Google::Cloud::Eventarc::Publishing::V1bproto3'
, true);
diff --git a/src/V1/Gapic/PublisherGapicClient.php b/src/V1/Gapic/PublisherGapicClient.php
index aa4ac37..37ed2ae 100644
--- a/src/V1/Gapic/PublisherGapicClient.php
+++ b/src/V1/Gapic/PublisherGapicClient.php
@@ -35,6 +35,8 @@
use Google\Auth\FetchAuthTokenInterface;
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsRequest;
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse;
+use Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest;
+use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse;
use Google\Protobuf\Any;
/**
@@ -253,4 +255,63 @@ public function publishChannelConnectionEvents(array $optionalArgs = [])
$request
)->wait();
}
+
+ /**
+ * Publish events to a subscriber's channel.
+ *
+ * Sample code:
+ * ```
+ * $publisherClient = new PublisherClient();
+ * try {
+ * $response = $publisherClient->publishEvents();
+ * } finally {
+ * $publisherClient->close();
+ * }
+ * ```
+ *
+ * @param array $optionalArgs {
+ * Optional.
+ *
+ * @type string $channel
+ * The full name of the channel to publish to. For example:
+ * `projects/{project}/locations/{location}/channels/{channel-id}`.
+ * @type Any[] $events
+ * The CloudEvents v1.0 events to publish. No other types are allowed.
+ * @type RetrySettings|array $retrySettings
+ * Retry settings to use for this call. Can be a
+ * {@see Google\ApiCore\RetrySettings} object, or an associative array of retry
+ * settings parameters. See the documentation on
+ * {@see Google\ApiCore\RetrySettings} for example usage.
+ * }
+ *
+ * @return \Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse
+ *
+ * @throws ApiException if the remote call fails
+ */
+ public function publishEvents(array $optionalArgs = [])
+ {
+ $request = new PublishEventsRequest();
+ $requestParamHeaders = [];
+ if (isset($optionalArgs['channel'])) {
+ $request->setChannel($optionalArgs['channel']);
+ $requestParamHeaders['channel'] = $optionalArgs['channel'];
+ }
+
+ if (isset($optionalArgs['events'])) {
+ $request->setEvents($optionalArgs['events']);
+ }
+
+ $requestParams = new RequestParamsHeaderDescriptor(
+ $requestParamHeaders
+ );
+ $optionalArgs['headers'] = isset($optionalArgs['headers'])
+ ? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
+ : $requestParams->getHeader();
+ return $this->startCall(
+ 'PublishEvents',
+ PublishEventsResponse::class,
+ $optionalArgs,
+ $request
+ )->wait();
+ }
}
diff --git a/src/V1/PublishEventsRequest.php b/src/V1/PublishEventsRequest.php
new file mode 100644
index 0000000..aea6d16
--- /dev/null
+++ b/src/V1/PublishEventsRequest.php
@@ -0,0 +1,105 @@
+google.cloud.eventarc.publishing.v1.PublishEventsRequest
+ */
+class PublishEventsRequest extends \Google\Protobuf\Internal\Message
+{
+ /**
+ * The full name of the channel to publish to. For example:
+ * `projects/{project}/locations/{location}/channels/{channel-id}`.
+ *
+ * Generated from protobuf field string channel = 1;
+ */
+ private $channel = '';
+ /**
+ * The CloudEvents v1.0 events to publish. No other types are allowed.
+ *
+ * Generated from protobuf field repeated .google.protobuf.Any events = 2;
+ */
+ private $events;
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * @type string $channel
+ * The full name of the channel to publish to. For example:
+ * `projects/{project}/locations/{location}/channels/{channel-id}`.
+ * @type \Google\Protobuf\Any[]|\Google\Protobuf\Internal\RepeatedField $events
+ * The CloudEvents v1.0 events to publish. No other types are allowed.
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Google\Cloud\Eventarc\Publishing\V1\Publisher::initOnce();
+ parent::__construct($data);
+ }
+
+ /**
+ * The full name of the channel to publish to. For example:
+ * `projects/{project}/locations/{location}/channels/{channel-id}`.
+ *
+ * Generated from protobuf field string channel = 1;
+ * @return string
+ */
+ public function getChannel()
+ {
+ return $this->channel;
+ }
+
+ /**
+ * The full name of the channel to publish to. For example:
+ * `projects/{project}/locations/{location}/channels/{channel-id}`.
+ *
+ * Generated from protobuf field string channel = 1;
+ * @param string $var
+ * @return $this
+ */
+ public function setChannel($var)
+ {
+ GPBUtil::checkString($var, True);
+ $this->channel = $var;
+
+ return $this;
+ }
+
+ /**
+ * The CloudEvents v1.0 events to publish. No other types are allowed.
+ *
+ * Generated from protobuf field repeated .google.protobuf.Any events = 2;
+ * @return \Google\Protobuf\Internal\RepeatedField
+ */
+ public function getEvents()
+ {
+ return $this->events;
+ }
+
+ /**
+ * The CloudEvents v1.0 events to publish. No other types are allowed.
+ *
+ * Generated from protobuf field repeated .google.protobuf.Any events = 2;
+ * @param \Google\Protobuf\Any[]|\Google\Protobuf\Internal\RepeatedField $var
+ * @return $this
+ */
+ public function setEvents($var)
+ {
+ $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Protobuf\Any::class);
+ $this->events = $arr;
+
+ return $this;
+ }
+
+}
+
diff --git a/src/V1/PublishEventsResponse.php b/src/V1/PublishEventsResponse.php
new file mode 100644
index 0000000..4291ac3
--- /dev/null
+++ b/src/V1/PublishEventsResponse.php
@@ -0,0 +1,33 @@
+google.cloud.eventarc.publishing.v1.PublishEventsResponse
+ */
+class PublishEventsResponse extends \Google\Protobuf\Internal\Message
+{
+
+ /**
+ * Constructor.
+ *
+ * @param array $data {
+ * Optional. Data for populating the Message object.
+ *
+ * }
+ */
+ public function __construct($data = NULL) {
+ \GPBMetadata\Google\Cloud\Eventarc\Publishing\V1\Publisher::initOnce();
+ parent::__construct($data);
+ }
+
+}
+
diff --git a/src/V1/PublisherGrpcClient.php b/src/V1/PublisherGrpcClient.php
index 95bf6f8..24bc424 100644
--- a/src/V1/PublisherGrpcClient.php
+++ b/src/V1/PublisherGrpcClient.php
@@ -70,4 +70,19 @@ public function PublishChannelConnectionEvents(\Google\Cloud\Eventarc\Publishing
$metadata, $options);
}
+ /**
+ * Publish events to a subscriber's channel.
+ * @param \Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument input argument
+ * @param array $metadata metadata
+ * @param array $options call options
+ * @return \Grpc\UnaryCall
+ */
+ public function PublishEvents(\Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument,
+ $metadata = [], $options = []) {
+ return $this->_simpleRequest('/google.cloud.eventarc.publishing.v1.Publisher/PublishEvents',
+ $argument,
+ ['\Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse', 'decode'],
+ $metadata, $options);
+ }
+
}
diff --git a/src/V1/gapic_metadata.json b/src/V1/gapic_metadata.json
index cfd916e..ea1b74e 100644
--- a/src/V1/gapic_metadata.json
+++ b/src/V1/gapic_metadata.json
@@ -14,6 +14,11 @@
"methods": [
"publishChannelConnectionEvents"
]
+ },
+ "PublishEvents": {
+ "methods": [
+ "publishEvents"
+ ]
}
}
}
diff --git a/src/V1/resources/publisher_client_config.json b/src/V1/resources/publisher_client_config.json
index de9772a..4eca798 100644
--- a/src/V1/resources/publisher_client_config.json
+++ b/src/V1/resources/publisher_client_config.json
@@ -30,6 +30,11 @@
"timeout_millis": 60000,
"retry_codes_name": "no_retry_1_codes",
"retry_params_name": "no_retry_1_params"
+ },
+ "PublishEvents": {
+ "timeout_millis": 60000,
+ "retry_codes_name": "no_retry_codes",
+ "retry_params_name": "no_retry_params"
}
}
}
diff --git a/src/V1/resources/publisher_rest_client_config.php b/src/V1/resources/publisher_rest_client_config.php
index 4cf9771..dfd2669 100644
--- a/src/V1/resources/publisher_rest_client_config.php
+++ b/src/V1/resources/publisher_rest_client_config.php
@@ -15,6 +15,18 @@
],
],
],
+ 'PublishEvents' => [
+ 'method' => 'post',
+ 'uriTemplate' => '/v1/{channel=projects/*/locations/*/channels/*}:publishEvents',
+ 'body' => '*',
+ 'placeholders' => [
+ 'channel' => [
+ 'getters' => [
+ 'getChannel',
+ ],
+ ],
+ ],
+ ],
],
],
];
diff --git a/tests/Unit/V1/PublisherClientTest.php b/tests/Unit/V1/PublisherClientTest.php
index e848c30..c070d0a 100644
--- a/tests/Unit/V1/PublisherClientTest.php
+++ b/tests/Unit/V1/PublisherClientTest.php
@@ -29,6 +29,7 @@
use Google\ApiCore\Testing\MockTransport;
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse;
use Google\Cloud\Eventarc\Publishing\V1\PublisherClient;
+use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse;
use Google\Rpc\Code;
use stdClass;
@@ -121,4 +122,60 @@ public function publishChannelConnectionEventsExceptionTest()
$transport->popReceivedCalls();
$this->assertTrue($transport->isExhausted());
}
+
+ /**
+ * @test
+ */
+ public function publishEventsTest()
+ {
+ $transport = $this->createTransport();
+ $client = $this->createClient([
+ 'transport' => $transport,
+ ]);
+ $this->assertTrue($transport->isExhausted());
+ // Mock response
+ $expectedResponse = new PublishEventsResponse();
+ $transport->addResponse($expectedResponse);
+ $response = $client->publishEvents();
+ $this->assertEquals($expectedResponse, $response);
+ $actualRequests = $transport->popReceivedCalls();
+ $this->assertSame(1, count($actualRequests));
+ $actualFuncCall = $actualRequests[0]->getFuncCall();
+ $actualRequestObject = $actualRequests[0]->getRequestObject();
+ $this->assertSame('/google.cloud.eventarc.publishing.v1.Publisher/PublishEvents', $actualFuncCall);
+ $this->assertTrue($transport->isExhausted());
+ }
+
+ /**
+ * @test
+ */
+ public function publishEventsExceptionTest()
+ {
+ $transport = $this->createTransport();
+ $client = $this->createClient([
+ 'transport' => $transport,
+ ]);
+ $this->assertTrue($transport->isExhausted());
+ $status = new stdClass();
+ $status->code = Code::DATA_LOSS;
+ $status->details = 'internal error';
+ $expectedExceptionMessage = json_encode([
+ 'message' => 'internal error',
+ 'code' => Code::DATA_LOSS,
+ 'status' => 'DATA_LOSS',
+ 'details' => [],
+ ], JSON_PRETTY_PRINT);
+ $transport->addResponse(null, $status);
+ try {
+ $client->publishEvents();
+ // If the $client method call did not throw, fail the test
+ $this->fail('Expected an ApiException, but no exception was thrown.');
+ } catch (ApiException $ex) {
+ $this->assertEquals($status->code, $ex->getCode());
+ $this->assertEquals($expectedExceptionMessage, $ex->getMessage());
+ }
+ // Call popReceivedCalls to ensure the stub is exhausted
+ $transport->popReceivedCalls();
+ $this->assertTrue($transport->isExhausted());
+ }
}