The Java SDK for backends
The Java SDK is a backend SDK that can be used to communicate with Mitter.io. It provides the following high level functionalities:
- 1.Create and delete Users
- 2.Create and delete Channels
- 3.Get and send Messages
- 4.Get and send Timeline Events
Being a backend SDK, the Java SDK connects with Mitter.io via HTTP only.
The Java SDK is available on jcenter. Add this to you
compile group: 'io.mitter', name: 'java-sdk', version: '0.5.5'
The main point of access is the
MitterCentralClientFactory. Create the factory like so:
MitterCentralClientFactory factory = new MitterCentralClientFactory(
This will authenticate you with an Application Principal. This is the most common type of credential you will need when you make calls from your backend.
You can also authenticate as:
- 1.The Subscriber (the entity you created you Mitter.io account with) using
- 2.A User, using
- 3.Anonymously, using
Do note that each principal has restricted access to APIs. A Subscriber, for instance, cannot send Messages to a Channel, and an Application cannot create other Applications.
Refer to the Platform Reference docs for the full list of operations each Principal can perform.
You can access the different
Users operations are done through the
MitterUsersClient, as follows:
"princess-carolyn", //the userId
Channel operations are performed using the
MitterChannelsClient, which can be acquired and used as follows:
"bojack-intervention", //the channelId
"io.mitter.ruleset.chats.GroupChat", //the group chat ruleset
new ChannelParticipation(IdUtils.of("princess-carolyn", User.class)), //Converting a string to mitter Identifiable
new ChannelParticipation(IdUtils.of("mister-peanutbutter", User.class))
false // whether systemChannel or not
Send Messages using the
//Text of the message
"Welcome to BoJack's Intervention. Grab some popcorn",
//A list of TimelineEvents. You can send as many as you want
//mitter mandates that the SentTime MUST be sent
Send custom payloads:
//A text representation is mandatory, even for custom payload messages
"Here's some entertainment meanwhile",
//Send custom payloads
// Custom data type
// Send any JSON
Get very specific messages with a query:
// Fetch query for messages
// No. of messages to fetch
// 'beforeId': Fetch only before this message
// 'afterId': Fetch only after this message
// fetch messages with any of these payloadTypes only
The SDK has a few other clients for operations on Timeline Events, User Presence, Channel Streams, etc.
The APIs are very similar to the ones shown above, and you should have no problem navigating through them.
High Level Clients
Certain APIs on Mitter.io are paginated, like Channels and Messages. So when you do something like
messagesClient.getMessagesFromChannel(channelId)you will only get the default 50 messages, and to get more messages, you will have to build a query and call
The SDK makes it easy to use these paginated APIs without worrying about the pagination scheme or maintaining the pagination tokens, by providing high level clients.
MitterMessagesHlcClientprovides the following convenience functions:
You don't need to worry about these functions being intensive operations, because they provide lazy lists.
High Level Clients return
Iterators, so more pages will not be fetched unless you iterate and reach the end.
- The SDK is itself written in Kotlin, and fully supports most JVM languages
- To be able to send JSON in custom payloads, the SDK uses