HowTo - Using Pipelines for Webhook with Fallback
  • Updated on 21 Oct 2019
  • 1 minute to read
  • Contributors
  • Print
  • Share
  • Dark
    Light

HowTo - Using Pipelines for Webhook with Fallback

  • Print
  • Share
  • Dark
    Light

Webhook With Fallback

It's possible to create fallback options for output types by using a [try broker][try-broker]. In this article we'll explore this pattern by creating stream bridges that accept messages via an c8db collection endpoint and forwards the messages to a HTTP endpoint, and if it fails to do so will print the message to error stream as a warning.

{
	"input": {
		"type": "c8streams",
		"c8streams": {
			"name": "input-stream",
			"local": false
		}
	},
	"output": {
		"type": "broker",
		"broker": {
			"pattern": "try",
			"outputs": [{
					"type": "http_client",
					"http_client": {
						"url": "http://localhost/post",
						"verb": "POST",
						"backoff_on": [
							429
						],
						"drop_on": [
							409
						],
						"retries": 3
					}
				},
				{
					"type": "stdout",
					"processors": [{
						"type": "insert_part",
						"insert_part": "content: \"MESSAGE FAILED:\"\nindex: 0"
					}]
				}
			]
		}
	}
}

It's worth noting that we have added a processor on the fallback output which adds prefix content to the logged message. We could apply any processors here to
make arbitrary changes to the payload.

C8Pipelines will now attempt to send the payload to the configured http_client endpoint. If the endpoint isn't reachable then after a few seconds you should see something like this on error-stream:

MESSAGE FAILED:
hello world

Try playing around with inputs, fallback outputs and fallback processors.

Was this article helpful?