-
Notifications
You must be signed in to change notification settings - Fork 216
Description
Related issues
colerogers.change-eventfilters
dl-cf3v2-eventfitlers
colerogers.change-eventfilters
dl-cf3v2-cc-efs
[REQUIRED] Version info
node: v18.12.1
firebase-functions: 4.4.1
firebase-tools: 12.7.0
firebase-admin: 11.11.0
[REQUIRED] Test case
import { onMessagePublished, PubSubOptions, } from "firebase-functions/v2/pubsub"; exports.specialMessageListener = onMessagePublished( { topic: "myTopic", region: region, eventFilters: [ { attributes: "type", value: "specialMessage", }, ], } , myFunctionToHandleSpecialMessages ); function myFunctionToHandleSpecialMessages( event: CloudEvent<MessagePublishedData<any>> ): void { console.log(event.data.message.attributes); }
[REQUIRED] Steps to reproduce
create a function as below:
exports.specialMessageListener = onMessagePublished(
{
topic: "myTopic",
region: region,
eventFilters: [
{
attributes: "type",
value: "specialMessage",
},
],
} ,
myFunctionToHandleSpecialMessages
); `
Deploy the function. check the pubsub topic subscription details.
[REQUIRED] Expected behavior
when firebase is deployed the subscription filter is set and the firebase function only recives messages that match the subscription filter
[REQUIRED] Actual behavior
The filter is not set and the function is triggered on all pubsub messages sent to the topic
Were you able to successfully deploy your functions? yes
I don't think this is a bug so much as missing docs on how to add a filter to a pubsub subscription from firebase.
I have tried several ways to set the eventFilter and either I get a typescript error or the functions deploy but missing the filtters (see screen shoot under actual behavior).
In the docs the description is just says TODO (see below)
@taeold has several merges in firebase tools and functions repos that suggest the format should be like:
eventTrigger: { eventType: "pubsub_event", eventFilter: [ { attribute: "resource", value: "my-storage-bucket", }. { attribute: "appId", value: "12345", }. ] }
this is then supported by the extensions documentation that has the same structure in the yaml example however PubSubOptions nor EventHandlerOptions don't have eventTrigger
as a option. I have tried using eventFilter
in the the PubSubOption
like:
onMessagePublished( { topic: "myTopic", region: region, eventFilters: [ { attributes: "type", value: "specalMessage", }, ], } , myFunctionToHandleSpecalMessages );
This deploys fine but it doesn't set the filter. I have tried several other ways to set the filter with no luck. Can you help with an example of what I have missed please.
Thank you for the help.