Skip to content
Java library to publish messages to Mercure Hub!
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
gradle/wrapper
src/main/java/com/vitorvillar/mercure
.gitignore
LICENSE
README.md
build.gradle
gradlew
gradlew.bat
pom.xml
settings.gradle

README.md

Java library for Mercure

The goal of this library is to provide a quick way to publish messages on Mercure. If you don't know what Mercure is, take a look here: (https://github.com/dunglas/mercure).

Installing

You can install via Gradle or Maven. Whatever floats your boat. :)

Gradle:

implementation 'com.vitorvillar:mercure:1.0.0'

Maven:

<dependency>
  <groupId>com.vitorvillar</groupId>
  <artifactId>mercure</artifactId>
  <version>1.0.0</version>
  <type>pom</type>
</dependency>

How to use

This library is really simple to use, you just need to create a new Publisher and for each message you want to publish, just create a new Message object.

Here is an example:

package com.vitorvillar.test;

import com.vitorvillar.mercure.exceptions.HubNotFoundException;
import com.vitorvillar.mercure.exceptions.PublishRejectedException;
import com.vitorvillar.mercure.exceptions.UnauthorizedPublisherException;

public class Main {

    public static void main(String[] args) throws UnauthorizedPublisherException, PublishRejectedException, HubNotFoundException {
        var token = "your.secret.token";
        var data = "{\"test\": 10}";

        var publisher = new Publisher("http://localhost:3000/.well-known/mercure", token);
        var message = new Message(data, "mytopic");
        var result = publisher.publish(message);
        System.out.println("Message ID: " + result.getId().toString());
    }
}

Credits

Created and maintained by Vitor Villar vitor.luis98@gmail.com

You can’t perform that action at this time.