In early days, I've wrote a blog about Oracle Reference Architecture and concept of Schema on Read and Schema on Write. Schema on Read is well suitable for Data Lake, which may ingest any data as it is, without any transformation and preserve it for a long period of time.
At the same time you have two types of data - Streaming Data and Batch. Batch could be log files, RDBMS archives. Streaming data could be IoT, Sensors, Golden Gate replication logs.
Apache Kafka is very popular engine for acquiring streaming data. It has multiple advantages, like scalability, fault tolerance and high throughput. Unfortunately, Kafka is hard to manage. Fortunately, Cloud simplifies many routine operations. Oracle Has three options for deploy Kafka in the Cloud:
1) Use Big Data Cloud Service, where you get full Cloudera cluster and there you could deploy Apache Kafka as part of CDH.
2) Event Hub Cloud Service Dedicated. Here you have to specify server shapes and some other parameters, but rest done by Cloud automagically.
3) Event Hub Cloud Service. This service is fully managed by Oracle, you even don't need to specify any compute shapes or so. Only one thing to do is tell for how long you need to store data in this topic and tell how many partitions do you need (partitions = performance).
Today, I'm going to tell you about last option, which is fully managed cloud service.
It's really easy to provision it, just need to login into your Cloud account and choose "Event Hub" Cloud service.
after this go and choose open service console:
Next, click on "Create service":
Put some parameters - two key is Retention period and Number of partitions. First defines for how long will you store messages, second defines performance for read and write operations.
Click next after:
Confirm and wait a while (usually not more than few minutes):
after a short while, you will be able to see provisioned service:
Hello world flow.
Today I want to show "Hello world" flow. How to produce (write) and consume (read) message from Event Hub Cloud Service.
The flow is (step by step):
1) Obtain OAuth token
2) Produce message to a topic
3) Create consumer group
4) Subscribe to topic
5) Consume message
Now I'm going to show it in some details.
OAuth and Authentication token (Step 1)
In couple words OAuth token authorization (tells what I could access) method to restrict access to some resources.
One of the main idea is decouple Uses (real human - Resource Owner) and Application (Client). Real man knows login and password, but Client (Application) will not use it every time when need to reach Resource Server (which has some info or content). Instead of this, Application will get once a Authorization token and will use it for working with Resource Server. This is brief, here you may find more detailed explanation what is OAuth.
Obtain Token for Event Hub Cloud Service client.
As you could understand for get acsess to Resource Server (read as Event Hub messages) you need to obtain authorization token from Authorization Server (read as IDCS). Here, I'd like to show step by step flow how to obtain this token. I will start from the end and will show the command (REST call), which you have to run to get token:
as you can see there are many parameters required for obtain OAuth token.
Let's take a looks there you may get it. Go to the service and click on topic which you want to work with, there you will find IDCS Application, click on it:
After clicking on it, you will go be redirected to IDCS Application page. Most of the credentials you could find here. Click on Configuration:
On this page right away you will find ClientID and Client Secret (think of it like login and password):
look down and find point, called Resources:
Click on it
and you will find another two variables, which you need for OAuth token - Scope and Primary Audience.
One more required parameter - IDCS_URL, you may find in your browser:
you have almost everything you need, except login and password. Here implies oracle cloud login and password (it what you are using when login into http://myservices.us.oraclecloud.com):
Now you have all required credential and you are ready to write some script, which will automate all this stuff:
after running this script, you will have new file called access_token.json. Field access_token it's what you need:
Create Linux variable for it:
Well, now we have Authorization token and may work with our Resource Server (Event Hub Cloud Service).
Note: you also may check documentation about how to obtain OAuth token.
Produce Messages (Write data) to Kafka (Step 2)
The first thing that we may want to do is produce messages (write data to a Kafka cluster). To make scripting easier, it's also better to use some environment variables for common resources. For this example, I'd recommend to parametrize topic's end point, topic name, type of content to be accepted and content type. Content type is completely up to developer, but you have to consume (read) the same format as you produce(write). The key parameter to define is REST endpoint. Go to PSM, click on topic name and copy everything till "restproxy":
Also, you will need topic name, which you could take from the same window:
now we could write a simple script for produce one message to Kafka:
if everything will be fine, Linux console will return something like:
Create Consumer Group (Step 3)
The first step to read data from OEHCS is create consumer group. We will reuse environment variables from previous step, but just in case I'll include it in this script:
this script will generate output file, which will contain variables, that we will need to consume messages.
Subscribe to a topic (Step 4)
Now you are ready to subscribe for this topic (export environment variable if you didn't do this before):
If everything fine, this request will not return something.
Consume (Read) messages (Step 5)
Finally, we approach last step - consuming messages.
and again, it's quite simple curl request:
if everything works, like it supposed to work, you will have output like:
Today we saw how easy to create fully managed Kafka Topic in Event Hub Cloud Service and also we made a first steps into it - write and read message. Kafka is really popular message bus engine, but it's hard to manage. Cloud simplifies this and allow customers concentrate on the development of their applications.
here I also want to give some useful links:
1) If you are not familiar with REST API, I'd recommend you to go through this blog
2) There is online tool, which helps to validate your curl requests
3) Here you could find some useful examples of producing and consuming messages
4) If you are not familiar with OAuth, here is nice tutorial, which show end to end example