Skip to content

Commit a574422

Browse files
authored
docs: remove incorrect pubsub docs (#145)
1 parent bd00cc3 commit a574422

File tree

1 file changed

+0
-74
lines changed

1 file changed

+0
-74
lines changed

docs/README.md

-74
Original file line numberDiff line numberDiff line change
@@ -41,77 +41,3 @@ URL: http://localhost:8080/
4141
```
4242

4343
You can now use an IDE or other tooling to add breakpoints, step through your code and debug your function.
44-
45-
## Local testing of cloud events
46-
The setup for cloud functions that accept events is very similar to the instructions in the quickstart, with the following adjustments:
47-
48-
In your package.json, add a signature type (in bold) to your start command:
49-
<pre>
50-
"scripts": {
51-
"start": "functions-framework --target=helloWorld <b>--signature-type=event"</b>
52-
}
53-
</pre>
54-
55-
Upon running ```sh npm start ```, you'll see the function is still being served at http://localhost:8080/. However it is no longer accessible via GET requests from the browser. Instead, send a POST request where the request body conforms to the API defined by [push subscriptions](https://cloud.google.com/pubsub/docs/push).
56-
57-
### Submitting POST request to simulating a pubsub message
58-
59-
Create mockPubsub.json file with the following contents:
60-
```json
61-
{
62-
"message": {
63-
"attributes": {
64-
"key": "value"
65-
},
66-
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
67-
"messageId": "136969346945"
68-
},
69-
"subscription": "projects/myproject/subscriptions/mysubscription"
70-
}
71-
```
72-
73-
The file can be in any folder on your computer. From the terminal, goto the directory where ```mockPubsub.json``` is located, and run the following command assuming your cloud function is hosted locally on port 8080:
74-
```sh
75-
curl -d "@mockPubsub.json" -X POST \
76-
-H "Ce-Type: true" \
77-
-H "Ce-Specversion: true" \
78-
-H "Ce-Source: true" \
79-
-H "Ce-Id: true" \
80-
-H "Content-Type: application/json" \
81-
http://localhost:8080
82-
```
83-
84-
> In order to simulate a Cloud Event, you need to add the ```Ce-*``` headers, along with a _truthy_ value, to the request.
85-
86-
### Using pubsub emulator
87-
88-
Another way to test your cloud function pubsub endpoint is to use the [pubsub emulator](https://cloud.google.com/pubsub/docs/emulator). This allows you to use the pubsub notification from another service to trigger your cloud function.
89-
90-
The high level approach is to:
91-
1. Start the pubsub emulator
92-
2. Use the pubsub client library to create a subscription and set the pushEndpoint to http://localhost:8080.
93-
94-
After that, all notifications to the subscription topic will be pushed to your cloud function.
95-
96-
Sample script for creating subscription with pushEndpoint:
97-
98-
```js
99-
{ PubSub } require('@google-cloud/pubsub');
100-
101-
async function main() {
102-
const pubsub = new PubSub({
103-
apiEndpoint: 'localhost:8085', // Pubsub emulator endpoint
104-
projectId: 'myproject',
105-
});
106-
const topic = await pubsub.topic('my-topic');
107-
const [topicExists] = await topic.exists();
108-
if (!topicExists) {
109-
await topic.create();
110-
}
111-
const createSubscriptionResponse = await topic.createSubscription('my_subscription', {
112-
pushEndpoint: 'https://localhost:8080',
113-
});
114-
}
115-
116-
main();
117-
```

0 commit comments

Comments
 (0)