# Knative Eventing Tickets Sale Example This tutorial install the Conference Platform application using Helm, but it also adds the services to implement the Tickets Selling flow. While the flow of events is not really representative of how an Event-Driven application should be architected, it serves as an example of multiple producers and consumers of events using the CloudEvents SDK to react to other Services events. The implemented flow is shown in the following figure: ![Buy Tickets Flow](imgs/buy-tickets-flow.png) This extension of the Conference Platform adds a new set of services which emit and consume events to implement the flow: ![Selling Tickets Services](imgs/selling-tickets-services.png) - Queue Service: Serves as a queing mechanism to deal with demand, customers joins the queue and they are served in a first-come/first-served fashion. - Tickets Service: handle the available tickest for the event, it locks the tickets until the payment is completed. - Payments Service: Interface with a legacy bank system that is not event-driven and waits for payments to be authorized by the external service by polling and exposing the state using events. The following diagram shows the events that are emitted by each service: ![Selling Tickets Events](imgs/selling-tickets-events.png) This tutorial covers different implementations of Knative Eventing Brokers such as: - In Memory MultiTenant Broker (default) - [RabbitMQ broker](#replacing-in-memory-broker-for-rabbitmq-broker) - [Kafka Broker](#replacing-in-memory-broker-for-kafka-broker) ## Pre Requisites - Install [Knative Serving](https://knative.dev/docs/install/serving/install-serving-with-yaml/) and [Knative Eventing](https://knative.dev/docs/install/eventing/install-eventing-with-yaml/). - For Knative Serving make sure that you configure the DNS so you get URLs for your Knative Services. - For Knative Eventing install the In-Memory Channel and the MT-Channel based Broker. - Patch ConfigMap to support downstream API - Install the Conference Platform App using Helm and setting the `knativeDeploy` variable to `true` - Create a Knative Eventing Broker, install SockEye and create a trigger to see all the events ### Creating a Knative Eventing Broker ``` kubectl create -f - < kubectl get ksvc NAME URL LATESTCREATED LATESTREADY READY REASON fmtok8s-agenda http://fmtok8s-agenda.default.X.X.X.X.sslip.io fmtok8s-agenda-00001 fmtok8s-agenda-00001 True fmtok8s-api-gateway http://fmtok8s-api-gateway.default.X.X.X.X.sslip.io fmtok8s-api-gateway-00001 fmtok8s-api-gateway-00001 True fmtok8s-c4p http://fmtok8s-c4p.default.X.X.X.X.sslip.io fmtok8s-c4p-00001 fmtok8s-c4p-00001 True fmtok8s-email http://fmtok8s-email.default.X.X.X.X.sslip.io fmtok8s-email-00001 fmtok8s-email-00001 True ``` Now you can use the API-Gateway Knative Service URL to access the Conference Application: http://fmtok8s-api-gateway.default.X.X.X.X.sslip.io (X.X.X.X should be your loadbalancer IP). ### Installing Sockeye for monitoring events Sockeye will let you monitor the CloudEvents that are being sent by every service of the application ``` kubectl apply -f https://github.com/n3wscott/sockeye/releases/download/v0.7.0/release.yaml ``` Once again, you can list your Knative Services to find Sockeye URL: ``` kubectl get ksvc ``` It should now include Sockeye Knative Service: ``` sockeye http://sockeye.default.X.X.X.X.sslip.io sockeye-00001 sockeye-00001 True ``` ### Creating a trigger to see all the events going to the broker You need to let the Knative Eventing Broker to know that should send all the events in the Broker to Sockeye, you do this by creating a new Knative Eventing Trigger: ``` kubectl create -f - < k get broker NAME URL AGE READY REASON default http://broker-ingress.knative-eventing.svc.cluster.local/default/default 4d17h True kafka-broker http://kafka-broker-ingress.knative-eventing.svc.cluster.local/default/kafka-broker 6m14s True ``` ### Updating the application to use the new Kafka Broker The API-Gateway Knative Service (`fmtok8s-api-gateway`) needs to be updated with a new K_SINK and K_SINK_POST_FIX variables. This is due the URL for the Kafka Broker is different from the In-Memory one. ``` - name: K_SINK value: http://kafka-broker-ingress.knative-eventing.svc.cluster.local - name: K_SINK_POST_FIX value: /broker/, /default/kafka-broker ``` For the same reason, we need update all application services dispatching events (`fmtok8s-agenda`, `fmtok8s-c4p `, `fmtok8s-email`, `queue-service`, `tickets-service`) to use the following `K_SINK`: ``` - name: K_SINK value: http://kafka-broker-ingress.knative-eventing.svc.cluster.local/default/kafka-broker ``` Finally, Knative Triggers cannot be patched to use the newly created Kafka Broker, hence new triggers will need to be created, for example, let's create the wildcard trigger for the Kafka Broker: ``` kubectl create -f - <