- Listen to the model data and generate events from it using Cloud Run functions.
- Send the Cloud Run functions generated events through the Pub/Sub event channel.
Supported models
The following models offer Cloud Run functions event generation and Pub/Sub event notification integrations:
- Occupancy analytics model
- Vertex AI custom-trained models
Before you begin
- Create an app with, at minimum, a stream node and a supported model node.
- Optional. Install the Vertex AI Vision SDK and ingest data into your app. If you don't do this before you set up event notification you must do it after.
- Optional. Create a Cloud Run function to use. If you don't create your Cloud Run function before you configure Cloud Run functions to process model output, you must create it during that process.
- Optional. Create a Pub/Sub topic to use. If you don't create your Pub/Sub topic before you enable model event notification with Pub/Sub, you must create it during that process.
- Optional. Choose and create a Pub/Sub subscription . If you don't create your Pub/Sub subscription before you enable model event notification with Pub/Sub, you must create it after to read messages from a topic.
Configure Cloud Run functions to process model output
To trigger event-based notifications, you must first set up Cloud Run functions to process model output and generate events.
Your Cloud Run function connects to the model and listens to its output
as its post-processing action. The Cloud Run function you should return
an AppPlatformCloudFunctionResponse
. The events
( appplatformeventbody
) are
sent to the Pub/Sub topic you configure in the next step.
Sample Cloud Run function (occupancy analytics model)
Sample Cloud Run function
/**
*
Responds
to
any
HTTP
request
.
*
*
@
param
{
!
express
:
Request
}
req
HTTP
request
context
.
*
@
param
{
!
express
:
Response
}
res
HTTP
response
context
.
*/
exports
.
hello_http
=
(
req
,
res
)
=
>
{
//
Logging
statement
can
be
read
with
cmd
`
gcloud
functions
logs
read
{
$
functionName
}
`
.
//
For
more
about
logging
,
please
see
https
:
//
cloud
.
google
.
com
/
functions
/
docs
/
monitoring
//
The
processor
output
will
be
stored
in
req
.
body
.
const
messageString
=
constructMessage
(
req
.
body
);
//
Send
your
message
to
operator
output
with
res
HTTP
response
context
.
res
.
status
(
200
)
.
send
(
messageString
);
};
function
constructMessage
(
data
)
{
//
Typically
,
your
processor
output
should
contains
appPlatformMetadata
&
it
's designed output.
//
Here
we
will
use
the
occupancy
analytics
model
as
an
example
.
const
appPlatformMetadata
=
data
.
appPlatformMetadata
;
const
annotations
=
data
.
annotations
;
const
events
=
[];
for
(
const
annotation
of
annotations
)
{
events
.
push
({
"event_message"
:
"Event message goes here"
,
"payload"
:
{
"attr_key_goes_here"
:
"val_goes_here"
},
"event_id"
:
"event_id_goes_here"
});
}
//
Typically
,
your
cloud
function
should
return
a
string
represent
a
JSON
which
has
two
fields
:
//
"annotations"
must
follow
the
specification
of
the
target
model
.
//
"events"
should
be
of
type
"AppPlatformEventBody"
.
const
messageJson
=
{
"annotations"
:
annotations
,
"events"
:
events
,
};
return
JSON
.
stringify
(
messageJson
);
}
Use the following instructions to to send the model output stream to your Cloud Run function:
Console
-
Open the Applicationstab of the Vertex AI Vision dashboard.
-
Select View appnext to the name of your application from the list.
-
Click on the supported model to open the model details side panel.
-
In the post-processinglist of the Event notificationsection, select your existing Cloud Run function, or create a new one.

Enable model event notification with Pub/Sub
After you have set up Cloud Run functions to process model output and generate events, you can set up event notification with Pub/Sub. To read messages from a topic, you also need to Choose and create a Pub/Sub subscription .
Console
-
Open the Applicationstab of the Vertex AI Vision dashboard.
-
Select View appnext to the name of your application from the list.
-
Click on the supported model to open the model details side panel.
-
In the Event notificationsection, select Set up event notification.
-
In the Set up Pub/Sub for event notificationsoption window that opens, choose your existing Pub/Sub topic, or create a new one.
-
In the Frequencyfield, set an integer value for the frequency value in seconds a notification for the same type of event can be sent.

-
Click Set up.
What's next
- Read instructions about how to deploy your app to test model event notification in Deploy and undeploy an application .
- Work through the Vertex AI Vision Occupancy Analytics app with event management codelab.
- Learn more about Pub/Sub and Cloud Run functions in What is Pub/Sub? and the Cloud Run functions overview .

