Skip to content

LAB2_Kesque

Cedrick Lunven edited this page Feb 2, 2021 · 22 revisions

๐ŸŽ“ LAB2 - Apache Pulsarโ„ข as a Service with Kesque.com


โœ… STEP 1: Sign up to Kesque.com

https://kesque.com is a Cloud Messaging service, fully managed and Powered by Apache Pulsarยฎ. It provides a free tier that you can use without providing any credit card.

Open https://kesque.com and locate the TRY FOR FREE button on the top right hand corner.

Register using existing account such as LinkedIn, Github, Twitter or create a new account with you address mail.

โœ… STEP 2: Create a Tenant

As you have no tenant yet you will be redirected to the tenant creation page.

  • For the tenant name you can pick what you like, I chose kesque-astra-demo, pick a name of your choice (A tenant name must be unique in the data center so kesque-astra-demo cannot be reused)

  • Click NEXT

  • For the datacenter name I picked uswest2.aws but any datacenter name should work. As it is used in the connection URL we recommended you to pick the same.

  • Click NEXT

  • Next screen will ask you to accept the general conditions by checking the checkbox.

  • Click NEXT

  • You get a summary screen, if you are ok with the values click Confirm

  • Once ready, you get the following page, click Let's GO

โœ… STEP 3: Discover your cluster

Let's open the different items in menu on the left to list which objects have been created for us. (SPOILER ALERT:it might be the same as we use for the LAB1)

  • Click the item Dashboard in the left menu. The dashboard shows you that we picked the datacenter uswest2-AWS and reminds you of the name of your tenant (for me kesque-astra-demo)

  • Click the item Plans/Manage in the left menu. It shows that we are using the free tier

  • Click the item Clusters in the left menu. It shows that the only object in the cluster as of now is a namespace

  • Click the item Namespaces in the left menu. It shows the empty namespace local-uswest2-aws which is the concatenation of local and the name of your datacenter uswest2-aws.

โœ… STEP 4: Create a topic

  • Click the item Topics in the left menu. Click the + Topic button to open the creation popup.

  • Provide topic name. We recommend to use astra it will be easier for mapping definition later. There is no need to check the Partitioned checkbox as in the free tier we are working on a single datacenter/namespace. Click OK.

  • The topic is now created and you can note that it has no producer, nor consumer. Let's change that.

Above, sample output no actions required

โœ… STEP 5: Retrieve your Authentication Token

To create a producer or consumer to connect to Kesque service you need 3 paramters:

  • A Service URL based on the datacenter name, here it will be pulsar+ssl://uswest2.aws.kafkaesque.io:6651.
โ„น๏ธ We are using the pulsar binary protocol but HTTP(https://uswest2.aws.kafkaesque.io:8085)
and websockets (wss://uswest2.aws.kafkaesque.io:8001) are also available 
(cf dashboard screen).
  • The topic URL built with the following pattern
persistent://<tenant_name>/<datacenter_name>/<topic_name>
  • An Authentication token, it is a long string of alphanumeric characters. For me the authentication token looks like:
eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJrZXNxdWUtYXN0cmEtZGVtby1jbGllbnQtNjAxNWRmODViODU5OCJ9.
m_FIe8kDrxUVPafsEyosLlnqllu5x7arDYeI7h9ag3GxCRrTELI_x9eTbfZ3TPdlI_i9m7Beu0VXsHLIt7u2Ji
hqvOXNUPqduKxs7y4_P3k0VfYOy3r8d9NRKParbNbVJqES_BsfF6DFOZIu1tdRAoitVQxbfLN42LgwqM3R8IBn
xpjJyGRjJA6VzPeh5QfZPtNLccqL_7Pt97tbL2YC9mYTFagSV68zsDEWbmRApkfzbMV5tgQuJZH4QBh_jHa9xs
TdWy5Adxkfv-ch_gAzhqnAOdnsY6SiimYJ2nlsiDfSL6-3jIJasJ2QAplk8TBumpRJN6SP4cAry6WWQSYvQ

To retrieve your token click Credentials in the left menu. Then, locate the banner Click to show connect token. You can copy the value of the token in your clipboard using the ellipsis on the right.

โœ… STEP 6: Create a producer in JAVA

Select the item Code Samples in the left menu to find code to create producer and consumer in multiple languages. For the demo we are using JAVA but if you feel confident you can use the language of your choice (we won't provide solutions)

We need you to execute a bit of Java, you need an IDE. We will use Gitpod. It is a 100% online IDE based on Eclipse Theia. To initialize your environment simply click on the button below (CTRL + Click to open in new tab) You will be asked for your github account.

Open in Gitpod

  • In the left panel (EXPLORER) locate the file application.properties in folder src/main/resources.

  • Open the file and replace the authentication token with the one you have in your clipboard (CTRL+V).

  • Replace value of key kesque.tenant_name with the name of YOUR tenant. (kesque-astra-demo is MINE).

Depending on the settings you provide you maybe have more keys to update like the tenant_name or the datacenter check instruction below.

# ---------------------------------------
# Configuration of your Kesque tenant
# ---------------------------------------

# BE GENTLE WITH THE FREE TIER
demo.wait_between_message=1000

# UPDATE THOSE KEYS IF YOU DID NOT PICK DATACENTER uswest2.aws
kesque.service_url=pulsar+ssl://uswest2.aws.kafkaesque.io:6651
kesque.namespace=local-uswest2-aws

# UPDATE THIS KEY WITH THE NAME OF YOUR TENANT
kesque.tenant_name=<your_tenant_name>

# UPDATE THIS KEY WITH YOUR AUTHENTICATIONT TOKEN
kesque.authentication_token=<your_token>

# Update this key if you used a different topic name
kesque.topic_name=astra

Open the class com.datastax.pulsar.SimplePulsarProducer and check that the code matches the sample code provided in the user interface. You might notice multiple differences:

  • We load properties into an object called DemoKesqueConfiguration. It can be reused in the multiple code samples we will execute.

  • We send a structured Object (DemoBean) and not a basic nor a JSON string because we want to work with a Schema. The producer is clever enough to marshall and unmarshall beans based on this JSON schema.

  • We use as few third party dependencies as possible to keep the code focused on Pulsar only. The pom.xml is empty.

pulsarClient = PulsarClient.builder()
  .serviceUrl(conf.getServiceUrl())
  .authentication(AuthenticationFactory.token(conf.getAuthenticationToken()))
  .build();
            
pulsarProducer = pulsarClient
  .newProducer(Schema.JSON(DemoBean.class))
  .topic("persistent://" 
     + conf.getTenantName() + "/" 
     + conf.getNamespace() + "/" 
     + conf.getTopicName())
  .create();
  • Make sure your are in the expected directory by executing the following command in the terminal
cd /workspace/workshop-pulsar/pulsar-demo
  • Then execute the following command to run the producer. SimplePulsarProducer will send a random message per second until it is stopped with (CTL+C)
mvn compile exec:java -Dexec.mainClass=com.datastax.pulsar.SimplePulsarProducer 

Expected output in the console:

[INFO] - Configuration has been loaded successfully
[PRODUCER] -  Message e08f1b9a-de38-4e27-9491-1ec24f7c08c8 sent
[PRODUCER] -  Message 219ad632-59a5-4054-8ad9-e0b6c91209da sent
[PRODUCER] -  Message a7bdba3f-975f-4345-986f-d2b327349c5a sent

  • In the Kesque user interface you can open the Topics details and see the producer is now there and the size of the topic is on the rise. Click details to see more

  • You can notice here more information is displayed like schema information or gauges. Click Producers to list producers

  • This is our little job running. Click Schemas to list schemas.

  • Very cool ! Message schema has been created with our first messages. The validation is not enabled but it will be helpful when it comes to map this messages into the database.

โœ… STEP 7: Messages in the User Interface

We know messages are coming, it is now time to show them. To do so we will use... consumer. Before jumping into the Consumer java code let's try the user interface and see what we can do here.

  • In the menu on the left pick Test Clients and setup the existing client to connect to our topic astra you need to edit the following properties.
Property Value
PRODUCER TOPIC astra
NAMESPACE local-uswest2-aws
SUBSCRIPTION NAME tc1-sub
TOPIC TYPE persistent
CONSUMER TOPIC astra
SUBSCRIPTION TYPE shared
KEY leave it blank

  • You can now click on Connect to see message coming:

  • You can copy paste one of the messages in the area YOUR MESSAGE and click SEND the message will appear both as produced and consumed with different colors.

  • (OPTIONAL) You can go back to the topic details page as detailed in STEP6 and list consumers and subscriptions

โœ… STEP 8: Create a consumer in JAVA

Now let's go back to JAVA. Good news everything is wired for you.

  • In GITPOD Open a new terminal in gitpod by locating the Split Terminal on the top left hand corner or the existing terminal

  • The new terminal opens beside the existing one....

  • Make sure your are in the expected directory by executing the following command
cd /workspace/workshop-pulsar/pulsar-demo
  • Run the consumer with the maven command below. You should now have both Producer and Consumer running in different terminals but visible in the same gitpod user interface AWESOME ๐Ÿ˜Ž
mvn exec:java -Dexec.mainClass=com.datastax.pulsar.SimplePulsarConsumer

  • Go back to Kesque UI, select Topics in the menu and look at the astra topics. You can have 2 producers, 2 consumers if you kept the web client running.

  • In the astra topic view click DETAILS. Then look for tabs Consumers and Subscriptions it should look like this for the consumer. Again, uou may have 2 lines if the web client (tc1-sub) is still running.

  • And for the subscriptions. Note that the subscription won't go away even if you kill the consumer (on the contrary of producers and consumers) so when done you may want to delete subscriptions from here.

๐Ÿ‘๐Ÿ‘ Bravo ! ๐Ÿ‘๐Ÿ‘ This is it for lab2. You know how to produce and consume messages from Kesque. In next Lab we will create a database to store all those funny messages.