How to connect to Azure Cosmos using the Java Cassandra Drivers

David North 0 Reputation points
2025-11-19T21:22:24.9633333+00:00

I have an existing application which uses Apache Cassandra, and I am attempting to check its compatibility with Azure Cosmos DB for Apache Cassandra

My application uses a recent 4.x version of the DataStax Java Driver for Cassandra (this has subsequently been adopted by Apache themselves).

To eliminate my app from the equation, I took the sample from here and tried it - then updated it to the newest driver and tried again:

https://github.com/Azure-Samples/azure-cosmos-db-cassandra-java-getting-started-v4/tree/master

No matter what I do, this is the error I get:

com.datastax.oss.driver.internal.core.protocol.FrameDecodingException: Error decoding frame for streamId 21584
        at com.datastax.oss.driver.internal.core.protocol.FrameDecoder.decode(FrameDecoder.java:108)
        at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1519)

...

Caused by: com.datastax.oss.driver.api.core.connection.FrameTooLongException: Adjusted frame length exceeds 268435456: 825110825 - discarded
[s0] Error connecting to Node(endPoint=xxxx.documents.azure.com/xxx:443, hostId=null, hashCode=1e66f887), trying next node 


What am I doing wrong? Can anyone provide the simplest possible working piece of Java which connects to Cosmos using a Cassandra driver?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
{count} votes

Answer recommended by moderator
  1. David North 0 Reputation points
    2025-11-19T21:48:32.4966667+00:00

    I eventually worked out that I need to use xxx.cassandra.cosmos.azure.com port 10350 - Microsoft's tutorial tells you to do this to look up your contact points:

     az cosmosdb show --resource-group "xxx" --name "yyy"  --query "{username:name,contactPoint:documentEndpoint}"
    

    This gives an incorrect hostname and an incorrect port (443).

    Looking in the Azure Console provided the answer.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Swapnesh Panchal 1,380 Reputation points Microsoft External Staff Moderator
    2025-11-20T00:52:00.16+00:00

    Hi @David North ,
    Welcome to the Microsoft Q&A and thank you for posting your questions here.
    The error occurs because the driver is connecting to the wrong endpoint and port. Azure Cosmos DB for Apache Cassandra requires the Cassandra API endpoint and CQL protocol over TLS.
    FrameTooLongException happens when the driver receives HTTPS from the SQL API endpoint instead of CQL frames. Switching to the Cassandra API endpoint resolves this.

    Key points:

    • Use your-account-name.cassandra.cosmos.azure.com on port 10350 (not *.documents.azure.com:443).
    • Enable SSL/TLS (driver does this by default for secure ports).
    • Username = account name; Password = primary key.
    • Set localDatacenter to the exact Azure region name of your account (e.g., "Region name").
    • Recommended consistency: LOCAL_QUORUM.
    • Dependencies: com.datastax.oss:java-driver-core:4.x

    If the issue persists, please share the required details in a private message.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.