class RestPayloadPublisher implements PayloadPublisher {

    @Override
    public void publishPayload(EncodedPayload payload, PublicKey recipientKey) {

        final Recipient retrievedRecipientFromStore =
                discovery.getCurrent().getRecipients().stream()
                        .filter(recipient -> recipientKey.equals(recipient.getKey()))
                        .findAny()
                        .orElseThrow(
                                () ->
                                        new KeyNotFoundException(
                                                "Recipient not found for key: " + recipientKey.encodeToBase64()));

        final String targetUrl = retrievedRecipientFromStore.getUrl();

        LOGGER.info("Publishing message to {}", targetUrl);

        final byte[] encoded = payloadEncoder.encode(payload);

        try (Response response =
                restclient
                        .target(targetUrl)
                        .path("/push")
                        .request()
                        .post(Entity.entity(encoded, MediaType.APPLICATION_OCTET_STREAM_TYPE))) {

            if (Response.Status.OK.getStatusCode() != response.getStatus()
                    && Response.Status.CREATED.getStatusCode() != response.getStatus()) {
                throw new PublishPayloadException("Unable to push payload to recipient url " + targetUrl);
            }

            LOGGER.info("Published to {}", targetUrl);
        } catch (ProcessingException ex) {
            LOGGER.debug("",ex);
            throw new NodeOfflineException(URI.create(targetUrl));
        }
    }

    public  RestPayloadPublisher(Client restclient, Discovery discovery);
    public  RestPayloadPublisher(Client restclient, PayloadEncoder payloadEncoder, Discovery discovery);

}