|
| 1 | +## Cloud Events with Spring samples |
| 2 | + |
| 3 | +### Introduction |
| 4 | +The current example uses spring-cloud-function framework as its core which allows users to only worry about functional aspects of |
| 5 | +their requirement while taking care-off non-functional aspects. For more information on Spring Cloud Function please visit |
| 6 | +our https://spring.io/projects/spring-cloud-function[project page]. |
| 7 | +The example provides dependency and instructions to demonstrate several distinct invocation models: |
| 8 | + |
| 9 | + - Direct function invocation |
| 10 | + - Function as a REST endpoint |
| 11 | + - Function as message handler (e.g., Kafka, RabbitMQ etc) |
| 12 | + - Function invocation via RSocket |
| 13 | + |
| 14 | +The POM file defines all the necessary dependency in a segregated way, so you can choose the one you're interested in. |
| 15 | + |
| 16 | +#### Direct function invocation |
| 17 | + |
| 18 | +#### Function as a REST endpoint |
| 19 | + |
| 20 | +Given that SCF allows function to be exposed as REST endpoints, you can post cloud event to any of the |
| 21 | +functions by using function name as path (e.g., localhost:8080/<function_name>) |
| 22 | + |
| 23 | +Here is an example of curl command posting a cloud event in binary-mode: |
| 24 | + |
| 25 | +[source, text] |
| 26 | +---- |
| 27 | +curl -w'\n' localhost:8080/asPOJO \ |
| 28 | + -H "ce-Specversion: 1.0" \ |
| 29 | + -H "ce-Type: com.example.springevent" \ |
| 30 | + -H "ce-Source: spring.io/spring-event" \ |
| 31 | + -H "Content-Type: application/json" \ |
| 32 | + -H "ce-Id: 0001" \ |
| 33 | + -d '{"releaseDate":"24-03-2004", "releaseName":"Spring Framework", "version":"1.0"}' |
| 34 | +---- |
| 35 | + |
| 36 | +And here is an example of curl command posting a cloud event in structured-mode: |
| 37 | + |
| 38 | +[source, text] |
| 39 | +---- |
| 40 | +curl -w'\n' localhost:8080/asString \ |
| 41 | + -H "ce-Specversion: 1.0" \ |
| 42 | + -H "ce-Type: com.example.springevent" \ |
| 43 | + -H "ce-Source: spring.io/spring-event" \ |
| 44 | + -H "Content-Type: application/cloudevents+json" \ |
| 45 | + -H "ce-Id: 0001" \ |
| 46 | + -d '{ |
| 47 | + "specversion" : "1.0", |
| 48 | + "type" : "org.springframework", |
| 49 | + "source" : "https://spring.io/", |
| 50 | + "id" : "A234-1234-1234", |
| 51 | + "datacontenttype" : "application/json", |
| 52 | + "data" : { |
| 53 | + "version" : "1.0", |
| 54 | + "releaseName" : "Spring Framework", |
| 55 | + "releaseDate" : "24-03-2004" |
| 56 | + } |
| 57 | +}' |
| 58 | +---- |
| 59 | + |
| 60 | +#### Function as message handler (e.g., Kafka, RabbitMQ etc) |
| 61 | + |
| 62 | +Streaming support for Kafka and Rabbit is provided via Spring Cloud Stream framework (link). In fact we're only mentioning Kafka and Rabbit here as an example. |
| 63 | +Streaming support is automatically provided for any existing binders (e.g., Solace, GCP, AWS etc) (link) |
| 64 | +Binders are components of SCSt responsible to bind user code (e.g., function) to broker destinations so execution is triggered |
| 65 | +by messages on broker destination and results of execution are sent to broker destinations. Binders also provide support consumer |
| 66 | +groups and partitioning for both Kafka and RabbitMQ messaging systems. |
| 67 | + |
| 68 | + |
| 69 | +#### Function invocation via RSocket |
| 70 | + |
| 71 | +TBD |
0 commit comments