Server SDK · Java & Spring
Java SDK
Java 11+ at runtime. Build with JDK 17+ and the included Gradle wrapper. Uses the JDK HTTP client and Gson.
Install from GitHub
The SDK source is public on the main branch. These instructions use Git or a locally built package; package registry releases are a separate step.
git clone --branch main https://github.com/pubbio/sdk-java.git
cd sdk-java
./gradlew publishSdkPublicationToLocalBuildRepository
# Add to your application's build.gradle.kts:
# repositories {
# maven { url = uri("/absolute/path/to/sdk-java/build/repository") }
# mavenCentral()
# }
# dependencies { implementation("io.pubb:pubb-java:0.2.0") }
Use the generated local Maven repository to resolve io.pubb:pubb-java:0.2.0. The repository README documents Gradle setup and HTTP client configuration.
Publish an event
Set PUBB_APP_ID, PUBB_APP_KEY and PUBB_APP_SECRET in your server environment, then publish after checking the caller's permissions.
import io.pubb.PubbServer;
import java.util.Map;
public class Publish {
public static void main(String[] args) throws Exception {
PubbServer pubb = new PubbServer(System.getenv("PUBB_APP_ID"),
System.getenv("PUBB_APP_KEY"), System.getenv("PUBB_APP_SECRET"));
PubbServer.TriggerResponse result = pubb.trigger("notifications", "message.sent",
Map.of("message", "Hello from Pubb!"));
System.out.println(result.publicationId);
}
}
For multiple channels, use the List<String> overload with TriggerOptions. Calls block and propagate IOException and InterruptedException; preserve the interrupt flag when catching interruption. A custom HttpClient must disable redirects and remains caller-owned.
HTTP 202 confirms acceptance for processing, not delivery. The response includes publicationId and duplicate. SDKs do not automatically retry publications; reuse an idempotency key when retrying the same event. The API accepts 1–100 channels and up to 10 KiB of UTF-8 JSON data.
Private and presence channels
Return the map from authorizeChannel(socketId, channel) or authorizePresenceChannel(socketId, channel, verifiedUserId, userInfo) after checking channel access. Serialize it as JSON in your backend framework.
Your backend receives socket_id and channel_name, checks the authenticated user’s access, and returns auth plus channel_data for presence. Derive the presence user ID from the session and forward the signed channel_data unchanged.
Keep the app secret on your trusted server. Public channels must not carry personal or restricted data. Read the channel access reference for the protocol.
Verify your integration
- Subscribe to
notificationsin your app or the dashboard’s Live console. - Publish
message.sentto the same application and channel from your backend. - Check the event payload, connection cleanup and recovery after a disconnect. Test denied access as well as successful private subscriptions.
The repositories include automated tests and examples. Verify end-to-end delivery with your own application before sending production traffic. Refetch durable state after reconnecting; missed events are not replayed.
Legacy pusher:* and pusher_internal:* control names are retained where required by the protocol. Their presence alone does not imply drop-in compatibility with every Pusher client or server.