Skip to content

Commit 3b9605f

Browse files
feat: [EventarcPublishing] Add publishing methods for channel resources (#5226)
* feat: Add publishing methods for channel resources PiperOrigin-RevId: 442858558 Source-Link: googleapis/googleapis@726dac2 Source-Link: googleapis/googleapis-gen@b2ecfcf Copy-Tag: eyJwIjoiRXZlbnRhcmNQdWJsaXNoaW5nLy5Pd2xCb3QueWFtbCIsImgiOiJiMmVjZmNmMjUyNDM2ZWJlMjEzNzY2NGVhNDFjZGNkMzNkMzZlMmFmIn0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent edce5c0 commit 3b9605f

9 files changed

Lines changed: 303 additions & 5 deletions

File tree

EventarcPublishing/metadata/V1/Publisher.php

Lines changed: 10 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EventarcPublishing/src/V1/Gapic/PublisherGapicClient.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
use Google\Auth\FetchAuthTokenInterface;
3636
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsRequest;
3737
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse;
38+
use Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest;
39+
use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse;
3840
use Google\Protobuf\Any;
3941

4042
/**
@@ -253,4 +255,63 @@ public function publishChannelConnectionEvents(array $optionalArgs = [])
253255
$request
254256
)->wait();
255257
}
258+
259+
/**
260+
* Publish events to a subscriber's channel.
261+
*
262+
* Sample code:
263+
* ```
264+
* $publisherClient = new PublisherClient();
265+
* try {
266+
* $response = $publisherClient->publishEvents();
267+
* } finally {
268+
* $publisherClient->close();
269+
* }
270+
* ```
271+
*
272+
* @param array $optionalArgs {
273+
* Optional.
274+
*
275+
* @type string $channel
276+
* The full name of the channel to publish to. For example:
277+
* `projects/{project}/locations/{location}/channels/{channel-id}`.
278+
* @type Any[] $events
279+
* The CloudEvents v1.0 events to publish. No other types are allowed.
280+
* @type RetrySettings|array $retrySettings
281+
* Retry settings to use for this call. Can be a
282+
* {@see Google\ApiCore\RetrySettings} object, or an associative array of retry
283+
* settings parameters. See the documentation on
284+
* {@see Google\ApiCore\RetrySettings} for example usage.
285+
* }
286+
*
287+
* @return \Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse
288+
*
289+
* @throws ApiException if the remote call fails
290+
*/
291+
public function publishEvents(array $optionalArgs = [])
292+
{
293+
$request = new PublishEventsRequest();
294+
$requestParamHeaders = [];
295+
if (isset($optionalArgs['channel'])) {
296+
$request->setChannel($optionalArgs['channel']);
297+
$requestParamHeaders['channel'] = $optionalArgs['channel'];
298+
}
299+
300+
if (isset($optionalArgs['events'])) {
301+
$request->setEvents($optionalArgs['events']);
302+
}
303+
304+
$requestParams = new RequestParamsHeaderDescriptor(
305+
$requestParamHeaders
306+
);
307+
$optionalArgs['headers'] = isset($optionalArgs['headers'])
308+
? array_merge($requestParams->getHeader(), $optionalArgs['headers'])
309+
: $requestParams->getHeader();
310+
return $this->startCall(
311+
'PublishEvents',
312+
PublishEventsResponse::class,
313+
$optionalArgs,
314+
$request
315+
)->wait();
316+
}
256317
}

EventarcPublishing/src/V1/PublishEventsRequest.php

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EventarcPublishing/src/V1/PublishEventsResponse.php

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EventarcPublishing/src/V1/PublisherGrpcClient.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,19 @@ public function PublishChannelConnectionEvents(\Google\Cloud\Eventarc\Publishing
7070
$metadata, $options);
7171
}
7272

73+
/**
74+
* Publish events to a subscriber's channel.
75+
* @param \Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument input argument
76+
* @param array $metadata metadata
77+
* @param array $options call options
78+
* @return \Grpc\UnaryCall
79+
*/
80+
public function PublishEvents(\Google\Cloud\Eventarc\Publishing\V1\PublishEventsRequest $argument,
81+
$metadata = [], $options = []) {
82+
return $this->_simpleRequest('/google.cloud.eventarc.publishing.v1.Publisher/PublishEvents',
83+
$argument,
84+
['\Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse', 'decode'],
85+
$metadata, $options);
86+
}
87+
7388
}

EventarcPublishing/src/V1/gapic_metadata.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"methods": [
1515
"publishChannelConnectionEvents"
1616
]
17+
},
18+
"PublishEvents": {
19+
"methods": [
20+
"publishEvents"
21+
]
1722
}
1823
}
1924
}

EventarcPublishing/src/V1/resources/publisher_client_config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
"timeout_millis": 60000,
3131
"retry_codes_name": "no_retry_1_codes",
3232
"retry_params_name": "no_retry_1_params"
33+
},
34+
"PublishEvents": {
35+
"timeout_millis": 60000,
36+
"retry_codes_name": "no_retry_codes",
37+
"retry_params_name": "no_retry_params"
3338
}
3439
}
3540
}

EventarcPublishing/src/V1/resources/publisher_rest_client_config.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
],
1616
],
1717
],
18+
'PublishEvents' => [
19+
'method' => 'post',
20+
'uriTemplate' => '/v1/{channel=projects/*/locations/*/channels/*}:publishEvents',
21+
'body' => '*',
22+
'placeholders' => [
23+
'channel' => [
24+
'getters' => [
25+
'getChannel',
26+
],
27+
],
28+
],
29+
],
1830
],
1931
],
2032
];

EventarcPublishing/tests/Unit/V1/PublisherClientTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Google\ApiCore\Testing\MockTransport;
3030
use Google\Cloud\Eventarc\Publishing\V1\PublishChannelConnectionEventsResponse;
3131
use Google\Cloud\Eventarc\Publishing\V1\PublisherClient;
32+
use Google\Cloud\Eventarc\Publishing\V1\PublishEventsResponse;
3233
use Google\Rpc\Code;
3334
use stdClass;
3435

@@ -121,4 +122,60 @@ public function publishChannelConnectionEventsExceptionTest()
121122
$transport->popReceivedCalls();
122123
$this->assertTrue($transport->isExhausted());
123124
}
125+
126+
/**
127+
* @test
128+
*/
129+
public function publishEventsTest()
130+
{
131+
$transport = $this->createTransport();
132+
$client = $this->createClient([
133+
'transport' => $transport,
134+
]);
135+
$this->assertTrue($transport->isExhausted());
136+
// Mock response
137+
$expectedResponse = new PublishEventsResponse();
138+
$transport->addResponse($expectedResponse);
139+
$response = $client->publishEvents();
140+
$this->assertEquals($expectedResponse, $response);
141+
$actualRequests = $transport->popReceivedCalls();
142+
$this->assertSame(1, count($actualRequests));
143+
$actualFuncCall = $actualRequests[0]->getFuncCall();
144+
$actualRequestObject = $actualRequests[0]->getRequestObject();
145+
$this->assertSame('/google.cloud.eventarc.publishing.v1.Publisher/PublishEvents', $actualFuncCall);
146+
$this->assertTrue($transport->isExhausted());
147+
}
148+
149+
/**
150+
* @test
151+
*/
152+
public function publishEventsExceptionTest()
153+
{
154+
$transport = $this->createTransport();
155+
$client = $this->createClient([
156+
'transport' => $transport,
157+
]);
158+
$this->assertTrue($transport->isExhausted());
159+
$status = new stdClass();
160+
$status->code = Code::DATA_LOSS;
161+
$status->details = 'internal error';
162+
$expectedExceptionMessage = json_encode([
163+
'message' => 'internal error',
164+
'code' => Code::DATA_LOSS,
165+
'status' => 'DATA_LOSS',
166+
'details' => [],
167+
], JSON_PRETTY_PRINT);
168+
$transport->addResponse(null, $status);
169+
try {
170+
$client->publishEvents();
171+
// If the $client method call did not throw, fail the test
172+
$this->fail('Expected an ApiException, but no exception was thrown.');
173+
} catch (ApiException $ex) {
174+
$this->assertEquals($status->code, $ex->getCode());
175+
$this->assertEquals($expectedExceptionMessage, $ex->getMessage());
176+
}
177+
// Call popReceivedCalls to ensure the stub is exhausted
178+
$transport->popReceivedCalls();
179+
$this->assertTrue($transport->isExhausted());
180+
}
124181
}

0 commit comments

Comments
 (0)