DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • NoSQL for Relational Minds
  • SQL Interview Preparation Series: Mastering Questions and Answers Quickly
  • Exploring the New Eclipse JNoSQL Version 1.1.0: A Dive Into Oracle NoSQL
  • Navigating NoSQL: A Pragmatic Approach for Java Developers

Trending

  • Assessing Bias in AI Chatbot Responses
  • Mastering Deployment Strategies: Navigating the Path to Seamless Software Releases
  • How Can Developers Drive Innovation by Combining IoT and AI?
  • Navigating Double and Triple Extortion Tactics
  1. DZone
  2. Data Engineering
  3. Databases
  4. Integrating NoSQL Database With Mule 4 (OOTB Cassandra Connector)

Integrating NoSQL Database With Mule 4 (OOTB Cassandra Connector)

Learn how to add a Cassandra database connector to the AnyPoint Studio in Mule 4 in this integration tutorial.

By 
Prathamesh Kulkarni user avatar
Prathamesh Kulkarni
·
Jan. 14, 21 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
5.3K Views

Join the DZone community and get the full member experience.

Join For Free

What Is a NoSQL Database?

A NoSQL database provides a mechanism to store and retrieve data other than the tabular relations used in relational databases. These databases are schema-free, support easy replication, have simple APIs, are eventually consistent, and can handle huge amounts of data.

The primary objective of a NoSQL database is to have:

  • Simple design
  • Horizontal scaling
  • Fine control over availability

What Is Cassandra?

Apache Cassandra is an open-source, distributed, and decentralized/distributed storage system (database) for managing very large amounts of structured data spread out across the world. It provides highly available service with no single point of failure.

The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance.

Mulesoft has a connector for Cassandra. The Cassandra connector provides connectivity between the Cassandra database system and REST API.

First of all, you will need to create a Mule project. Anypoint Studio and Mule Runtime 4.2.0 EE are used for the examples below.

How to Install Cassandra on Your System

Hit this link to go to the Cassandra Download page: http://cassandra.apache.org/download/.

Step 1

  • Extract the zip file apache-cassandra-3.11.4 to Local disk C
  • Set the Environment variable CASSANDRA_HOME as shown in the below screenshot.
  • Similarly, set the path of Cassandra. 
  • To run Cassandra, we also need to have JDK as well as Python.
    Link to download Python is: https://www.python.org/download/releases/2.7/.
  • Set the Environment variable for Python as shown in the screenshot below.

Step 2

  • Run the Cassandra on your local system and make sure it is up and running without any problem.
  • To run Cassandra, copy the path of the Cassandra folder up to bin and change the working directory to the above copied path. 
  •  cd C:\apache-cassandra-3.11.4\bin and hit Enter.
  • Enter Cassandra and hit Enter. Now, your Cassandra is starting.

Open another CMD and enter the command as cqlsh and proceed. 

Cassandra is up and running successfully.

How to Add Cassandra DB Connector to the AnyPoint Studio

Go to Add Modules and search for Cassandra. Add it and finish the task.

Setup & Configuration

Select the Cassandra connector and proceed. You will be able to see the Cassandra connector in Mule Palette. 

There are two ways to configure the Cassandra:

  1. Using your localhost
  2. Using Cluster Configuration

I have used the localhost. The default port for cassandra is 9042.

Drag a Cassandra component for Create Keyspace onto the canvas.

I have kept the keyspace as empty as I want to create the keyspace dynamically. 

While creating the keyspace, you need to give the replication factor as well as replicationStrategyClass and pass it as a Java object. The below screenshot will give you an idea of how to pass the payload. 

You can run the application and hit the created API with the proper request body.

You can see the keyspace has been created. In order to cross verify you can goto cmd and get the list of all keyspaces, you should see your keyspace.

How to Create Table

We have the component in the Cassandra called Create Table. Drag it from the Mule palette and create a new flow.

Set the payload in the transform message as shown in the below screenshot.

Here, you need to specify columns as well as the datatype of the column and whether it is a primary key. If you want the column to be the primary key, then set it as true.

In the postman, set the body like the below screenshot.

As you can see, right now, there is no table in the keyspace.

After hitting the API, Your table will get created with the name cassandra_demo.

The table is created with the given table name. Now, it’s time to insert data into the table.

How to Insert Data

For this, Mulesoft has provided us with an Insert Data component under the Cassandra Connector. So, you just have to drag that component and create a new flow with the different endpoint.

The Cassandra Module uses Java maps as the mechanism to define how data is inserted in a Cassandra key space.

Here, I am using batch step. The reason I am using batch step is we won’t be able to insert multiple records in the single hit and similarly to get the response back I am using VM publish and consume as batch job works Asynchronously.

I have used a select component in the same flow. You can go through the XML screenshot to get a better idea. Also, there are other components like delete, update, etc. and you can try it on your own.

Request Body of Insert Data 

I have logged the response of select.


XML code screenshot for reference:


Flow diagram:


Database Relational database Connector (mathematics) NoSQL

Opinions expressed by DZone contributors are their own.

Related

  • NoSQL for Relational Minds
  • SQL Interview Preparation Series: Mastering Questions and Answers Quickly
  • Exploring the New Eclipse JNoSQL Version 1.1.0: A Dive Into Oracle NoSQL
  • Navigating NoSQL: A Pragmatic Approach for Java Developers

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!