Skip to content

Base release

Compare
Choose a tag to compare
@WalshyDev WalshyDev released this 25 Feb 20:23
· 17 commits to master since this release
9c26b60

Start of the WebHookDistributor system. Full implementation client and server side. Code below as an example of client side.

For server just build and use.

Example class:

import org.slf4j.LoggerFactory;
import stream.flarebot.webhook_distributor.WebHookDistributor;
import stream.flarebot.webhook_distributor.WebHookDistributorBuilder;
import stream.flarebot.webhook_distributor.WebHookListener;
import stream.flarebot.webhook_distributor.events.WebHookReceiveEvent;

public class Example {

    public static void main(String[] args) {
    	// This will say that the server is located at "https://cool-webhooks.flarebot.stream", the service is called "example" and the port for this service is '8181'.
        WebHookDistributor distributor = new WebHookDistributorBuilder("https://cool-webhooks.flarebot.stream", "example", 8181)
        	// This will add the listener which is defined below.
                .addEventListener(new Listener())
                // This is the starting retry time, when connection to the server fails it will use this value first and double each failed attempt.
                .setStartingRetryTime(500)
                // The amount of connection attempts to make to the server before giving up.
                .setMaxConnectionAttempts(5)
                .build();
		// Start listening to WebHooks from the server.
        distributor.start();
    }

    private static class Listener extends WebHookListener {

        public void onWebHookReceive(WebHookReceiveEvent e){
            LoggerFactory.getLogger(Example.class).info(String.format("Received webhook from %s, data: %s",
                    e.getSender().toString(), e.getPayload().toString()));
        }
    }
}