GithubHelp home page GithubHelp logo

isabella232 / hop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rabbitmq/hop

0.0 0.0 0.0 1.82 MB

RabbitMQ HTTP API client for Java, Groovy, and other JVM languages

HTML 0.12% CSS 2.38% Java 59.69% Groovy 37.48% Shell 0.33%

hop's Introduction

Hop, Java Client for the RabbitMQ HTTP API

Build Status

Hop is a Java client for the RabbitMQ HTTP API.

Polyglot

Hop is designed to be easy to use from other JVM languages, primarily Groovy, Scala, and Kotlin.

N.B. that Clojure already includes an HTTP API client as part of Langohr, and you should use Langohr instead.

Reactive

As of Hop 2.1.0, a new reactive, non-blocking IO client based on Reactor Netty is available. Note the original blocking IO client remains available.

Project Maturity

This project is mature and covers all key RabbitMQ HTTP API endpoints.

Meaningful breaking API changes are reflected in the version. User documentation is currently kept in this README.

Maven Artifacts

Maven Central

Project artifacts are available from Maven Central and repo.spring.io.

Maven

If you want to use the blocking IO client, add the following dependencies:

pom.xml
<dependency>
  <groupId>com.rabbitmq</groupId>
  <artifactId>http-client</artifactId>
  <version>3.9.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>5.3.0</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.11.3</version>
</dependency>

If you want to use the reactive, non-blocking IO client, add the following dependencies:

pom.xml
<dependency>
  <groupId>com.rabbitmq</groupId>
  <artifactId>http-client</artifactId>
  <version>3.9.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>io.projectreactor.netty</groupId>
  <artifactId>reactor-netty</artifactId>
  <version>1.0.0</version>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <version>2.11.3</version>
</dependency>

Gradle

If you want to use the blocking IO client, add the following dependencies:

build.gradle
compile "com.rabbitmq:http-client:3.9.0.RELEASE"
compile "org.springframework:spring-web:5.3.0"
compile "com.fasterxml.jackson.core:jackson-databind:2.11.3"

If you want to use the reactive, non-blocking IO client, add the following dependencies:

build.gradle
compile "com.rabbitmq:http-client:3.9.0.RELEASE"
compile "io.projectreactor.netty:reactor-netty:1.0.0"
compile "com.fasterxml.jackson.core:jackson-databind:2.11.3"

Milestones and Release Candidates

Milestones and release candidates are available on the RabbitMQ Milestone Repository:

Maven:

pom.xml
<repositories>
<repository>
  <id>packagecloud-rabbitmq-maven-milestones</id>
  <url>https://packagecloud.io/rabbitmq/maven-milestones/maven2</url>
  <releases>
    <enabled>true</enabled>
  </releases>
  <snapshots>
    <enabled>false</enabled>
  </snapshots>
  </repository>
</repositories>

Gradle:

build.gradle
repositories {
  maven {
    url "https://packagecloud.io/rabbitmq/maven-milestones/maven2"
  }
}

Usage Guide

Instantiating a Client

Hop faithfully follows RabbitMQ HTTP API conventions in its API. You interact with the server using a single class, Client, which needs an API endpoint and a pair of credentials to be instantiated:

import com.rabbitmq.http.client.Client;
import com.rabbitmq.http.client.ClientParameters;

Client c = new Client(
  new ClientParameters()
    .url("http://127.0.0.1:15672/api/")
    .username("guest")
    .password("guest")
);

HTTP Layer

The HTTP layer used by the Client is pluggable. The Client(ClientParameters) constructor uses standard JDK HTTP facilities by default, but Apache HTTP Components and OkHttp are also supported.

Apache HTTP Components

To use Apache HTTP Components, use an HttpComponentsRestTemplateConfigurator instance when creating the client:

Client client = new Client(
    new ClientParameters().url("http://localhost:15672/api").username("guest").password("guest")
     .restTemplateConfigurator(new HttpComponentsRestTemplateConfigurator())
);

This requires to add Apache HTTP Components on the classpath.

For Maven:

pom.xml
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.13</version>
</dependency>

For Gradle:

build.gradle
compile "org.apache.httpcomponents:httpclient:4.5.13"

OkHttp

To use OkHttp, use an OkHttpRestTemplateConfigurator instance when creating the client:

Client client = new Client(
    new ClientParameters().url("http://localhost:15672/api").username("guest").password("guest")
     .restTemplateConfigurator(new OkHttpRestTemplateConfigurator())
);

This requires to add OkHttp on the classpath.

For Maven:

pom.xml
<dependency>
  <groupId>com.squareup.okhttp3</groupId>
  <artifactId>okhttp</artifactId>
  <version>3.14.9</version>
</dependency>

For Gradle:

build.gradle
compile "com.squareup.okhttp3:okhttp:3.14.9"

Getting Overview

c.getOverview();

Node and Cluster Status

// list cluster nodes
c.getNodes();

// get status and metrics of individual node
c.getNode("[email protected]");

Operations on Connections

// list client connections
c.getConnections();

// get status and metrics of individual connection
c.getConnection("127.0.0.1:61779 -> 127.0.0.1:5672");

// forcefully close connection
c.closeConnection("127.0.0.1:61779 -> 127.0.0.1:5672");

Operations on Channels

// list all channels
c.getChannels();

// list channels on individual connection
c.getChannels("127.0.0.1:61779 -> 127.0.0.1:5672");

// list detailed channel info
c.getChannel("127.0.0.1:61779 -> 127.0.0.1:5672 (3)");

Operations on Vhosts

// get status and metrics of individual vhost
c.getVhost("/");

Managing Users

TBD

Managing Permissions

TBD

Operations on Exchanges

TBD

Operations on Queues

// list all queues
c.getQueues();

// list all queues in a vhost
c.getQueues();

// declare a queue that's not durable, auto-delete,
// and non-exclusive
c.declareQueue("/", "queue1", new QueueInfo(false, true, false));

// bind a queue
c.bindQueue("/", "queue1", "amq.fanout", "routing-key");

// delete a queue
c.deleteQueue("/", "queue1");

Operations on Bindings

// list bindings where exchange "an.exchange" is source
// (other things are bound to it)
c.getBindingsBySource("/", "an.exchange");

// list bindings where exchange "an.exchange" is destination
// (it is bound to other exchanges)
c.getBindingsByDestination("/", "an.exchange");

Running Tests (with Docker)

Start the broker:

docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.8-management

Configure the broker for the test suite:

export HOP_RABBITMQCTL="DOCKER:rabbitmq"
./bin/before_build.sh

Launch the test suite:

./mvnw test

Running Tests

To run the suite against a specific RabbitMQ node, export HOP_RABBITMQCTL and HOP_RABBITMQ_PLUGINS to point at rabbitmqctl and rabbitmq-plugins from the installation.

Then set up the node that is assumed to be running:

./bin/before_build.sh

This will enable several plugins used by the test suite and configure the node to use a much shorter event refresh interval so that HTTP API reflects system state changes with less of a delay.

To run the tests:

./mvnw test

The test suite assumes RabbitMQ is running locally with stock settings and a few plugins are enabled:

  • rabbitmq_management (listening on port 15672)

  • rabbitmq_shovel_management

  • rabbitmq_federation_management

To run the suite against a specific RabbitMQ node, export HOP_RABBITMQCTL and HOP_RABBITMQ_PLUGINS to point at rabbitmqctl and rabbitmq-plugins from the installation.

The test suite can use a different port than 15672 by specifying it with the rabbitmq.management.port system property:

./mvnw test -Drabbitmq.management.port=15673

Versioning

This library uses semantic versioning.

Support

See the RabbitMQ Java libraries support page for the support timeline of this library.

License

Michael Klishin, 2014-2016.

VMware, Inc. or its affiliates, 2014-2020.

hop's People

Contributors

acogoluegnes avatar alenkacz avatar artembilan avatar ayoug avatar cwhittick avatar ddneat avatar deadtrickster avatar don-vip avatar emersonkopp avatar garyrussell avatar jokogr avatar jonasgao avatar kubamarchwicki avatar kurenchuksergey avatar lukebakken avatar marcialrosales avatar mhewedy avatar michaelklishin avatar nechkin avatar smonasco avatar spring-builds avatar spring-operator avatar vikinghawk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.