Skip to content

Commit

Permalink
spring-projectsGH-861: Quick Tour Docs Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell committed Dec 1, 2018
1 parent 1195658 commit abe27d7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
58 changes: 56 additions & 2 deletions src/reference/asciidoc/quick-tour.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,24 @@ The minimum `amqp-client` java client library version is 5.0.0.

===== Very, Very Quick

**Imports for the following Java examples**

====
[source, java]
----
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
----
====

Using plain, imperative Java to send and receive a message:

====
[source,java]
----
ConnectionFactory connectionFactory = new CachingConnectionFactory();
Expand All @@ -45,16 +61,18 @@ AmqpTemplate template = new RabbitTemplate(connectionFactory);
template.convertAndSend("myqueue", "foo");
String foo = (String) template.receiveAndConvert("myqueue");
----
====

Note that there is a `ConnectionFactory` in the native Java Rabbit client as well.
We are using the Spring abstraction in the code above.
We are using the Spring abstraction in the code above; it caches channels (and optionally connections) for reuse.
We are relying on the default exchange in the broker (since none is specified in the send), and the default binding of all queues to the default exchange by their name (hence we can use the queue name as a routing key in the send).
Those behaviours are defined in the AMQP specification.
Those behaviors are defined in the AMQP specification.

===== With XML Configuration

The same example as above, but externalizing the resource configuration to XML:

====
[source,java]
----
ApplicationContext context =
Expand Down Expand Up @@ -84,6 +102,7 @@ String foo = (String) template.receiveAndConvert("myqueue");
</beans>
----
====

The `<rabbit:admin/>` declaration by default automatically looks for beans of type `Queue`, `Exchange` and `Binding` and declares them to the broker on behalf of the user, hence there is no need to use that bean explicitly in the simple Java driver.
There are plenty of options to configure the properties of the components in the XML schema - you can use auto-complete features of your XML editor to explore them and look at their documentation.
Expand All @@ -92,6 +111,7 @@ There are plenty of options to configure the properties of the components in the

The same example again with the external configuration in Java:

====
[source,java]
----
ApplicationContext context =
Expand Down Expand Up @@ -126,3 +146,37 @@ public class RabbitConfiguration {
}
}
----
====

===== With Spring Boot Auto Configuration and an Async POJO Listener

Spring Boot automatically configures the infrastructure beans:

====
[source, java]
----
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ApplicationRunner runner(AmqpTemplate template) {
return args -> template.convertAndSend("myqueue", "foo");
}
@Bean
public Queue myQueue() {
return new Queue("myqueue");
}
@RabbitListener(queues = "myqueue")
public void listen(String in) {
System.out.println(in);
}
}
----
====
2 changes: 1 addition & 1 deletion src/reference/asciidoc/whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

===== AMQP Client library

Spring AMQP now uses the new 5.2.x version of the `amqp-client` library provided by the RabbitMQ team.
Spring AMQP now uses the 5.4.x version of the `amqp-client` library provided by the RabbitMQ team.
This client has auto recovery configured by default; see <<auto-recovery>>.

NOTE: As of version 4.0, the client enables automatic recovery by default; while compatible with this feature, Spring AMQP has its own recovery mechanisms and the client recovery feature generally isn't needed.
Expand Down

0 comments on commit abe27d7

Please sign in to comment.