reference = new AtomicReference<>();
46 | client = AmqpClient.create(vertx, new AmqpClientOptions()
47 | .setHost("localhost")
48 | .setPort(server.actualPort()));
49 | client.connect()
50 | .onComplete(connection -> {
51 | reference.set(connection.result());
52 | if (connection.failed()) {
53 | connection.cause().printStackTrace();
54 | }
55 | latch.countDown();
56 | });
57 |
58 | assertThat(latch.await(6, TimeUnit.SECONDS)).isTrue();
59 | this.connection = reference.get();
60 | assertThat(connection).isNotNull();
61 | this.address = UUID.randomUUID().toString();
62 | }
63 |
64 | @After
65 | public void tearDown() throws InterruptedException {
66 | super.tearDown();
67 | server.close();
68 | }
69 |
70 | @Test(timeout = 10000)
71 | public void test(TestContext context) throws Exception {
72 | connection.createSender(address)
73 | .compose(sender -> {
74 | AmqpMessage msg = AmqpMessage.create().withBooleanAsBody(true).build();
75 | return sender
76 | .write(msg);
77 | }).onComplete(context.asyncAssertFailure(expected -> {
78 | // Expected
79 | }));
80 | }
81 |
82 | private MockServer setupMockServer() throws Exception {
83 | return new MockServer(vertx, serverConnection -> {
84 | serverConnection.openHandler(serverSender -> {
85 | serverConnection.closeHandler(x -> serverConnection.close());
86 | serverConnection.open();
87 | });
88 |
89 | serverConnection.sessionOpenHandler(serverSession -> {
90 | serverSession.closeHandler(x -> serverSession.close());
91 | serverSession.open();
92 | });
93 |
94 | serverConnection.receiverOpenHandler(serverReceiver-> {
95 | serverReceiver.handler((delivery, message) -> {
96 | // Triggers message state to be null
97 | delivery.settle();
98 | });
99 |
100 | serverReceiver.open();
101 | });
102 | });
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/io/vertx/amqp/AmqpMessageBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2018-2019 The original author or authors
3 | *
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Eclipse Public License v1.0
6 | * and Apache License v2.0 which accompanies this distribution.
7 | *
8 | * The Eclipse Public License is available at
9 | * http://www.eclipse.org/legal/epl-v10.html
10 | *
11 | * The Apache License v2.0 is available at
12 | * http://www.opensource.org/licenses/apache2.0.php
13 | *
14 | * You may elect to redistribute this code under either of these licenses.
15 | */
16 | package io.vertx.amqp;
17 |
18 | import io.vertx.amqp.impl.AmqpMessageBuilderImpl;
19 | import io.vertx.codegen.annotations.GenIgnore;
20 | import io.vertx.codegen.annotations.VertxGen;
21 | import io.vertx.core.buffer.Buffer;
22 | import io.vertx.core.json.JsonArray;
23 | import io.vertx.core.json.JsonObject;
24 |
25 | import java.time.Instant;
26 | import java.util.List;
27 | import java.util.Map;
28 | import java.util.UUID;
29 |
30 | /**
31 | * Builder to create a new {@link AmqpMessage}.
32 | *
33 | * Reference about the different metadata can be found on
34 | * AMQP message properties.
35 | *
36 | * Note that the body is set using {@code withBodyAs*} method depending on the passed type.
37 | */
38 | @VertxGen
39 | public interface AmqpMessageBuilder {
40 |
41 | /**
42 | * @return a new instance of {@link AmqpMessageBuilder}
43 | */
44 | static AmqpMessageBuilder create() {
45 | return new AmqpMessageBuilderImpl();
46 | }
47 |
48 | /**
49 | * @return the message.
50 | */
51 | AmqpMessage build();
52 |
53 | // Headers
54 |
55 | AmqpMessageBuilder priority(short priority);
56 |
57 | AmqpMessageBuilder durable(boolean durable);
58 |
59 | AmqpMessageBuilder ttl(long ttl);
60 |
61 | AmqpMessageBuilder firstAcquirer(boolean first);
62 |
63 | AmqpMessageBuilder deliveryCount(int count);
64 |
65 | // Properties
66 |
67 | AmqpMessageBuilder id(String id);
68 |
69 | AmqpMessageBuilder address(String address);
70 |
71 | AmqpMessageBuilder replyTo(String replyTo);
72 |
73 | AmqpMessageBuilder correlationId(String correlationId);
74 |
75 | AmqpMessageBuilder withBody(String value);
76 |
77 | AmqpMessageBuilder withSymbolAsBody(String value);
78 |
79 | AmqpMessageBuilder subject(String subject);
80 |
81 | AmqpMessageBuilder contentType(String ct);
82 |
83 | AmqpMessageBuilder contentEncoding(String ct);
84 |
85 | AmqpMessageBuilder expiryTime(long expiry);
86 |
87 | AmqpMessageBuilder creationTime(long ct);
88 |
89 | AmqpMessageBuilder groupId(String gi);
90 |
91 | AmqpMessageBuilder replyToGroupId(String rt);
92 |
93 | AmqpMessageBuilder applicationProperties(JsonObject props);
94 |
95 | AmqpMessageBuilder withBooleanAsBody(boolean v);
96 |
97 | AmqpMessageBuilder withByteAsBody(byte v);
98 |
99 | AmqpMessageBuilder withShortAsBody(short v);
100 |
101 | AmqpMessageBuilder withIntegerAsBody(int v);
102 |
103 | AmqpMessageBuilder withLongAsBody(long v);
104 |
105 | AmqpMessageBuilder withFloatAsBody(float v);
106 |
107 | AmqpMessageBuilder withDoubleAsBody(double v);
108 |
109 | AmqpMessageBuilder withCharAsBody(char c);
110 |
111 | @GenIgnore(GenIgnore.PERMITTED_TYPE)
112 | AmqpMessageBuilder withInstantAsBody(Instant v);
113 |
114 | @GenIgnore(GenIgnore.PERMITTED_TYPE)
115 | AmqpMessageBuilder withUuidAsBody(UUID v);
116 |
117 | @GenIgnore
118 | AmqpMessageBuilder withListAsBody(List list);
119 |
120 | @GenIgnore
121 | AmqpMessageBuilder withMapAsBody(Map map);
122 |
123 | AmqpMessageBuilder withBufferAsBody(Buffer buffer);
124 |
125 | AmqpMessageBuilder withJsonObjectAsBody(JsonObject json);
126 |
127 | AmqpMessageBuilder withJsonArrayAsBody(JsonArray json);
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/generated/io/vertx/amqp/AmqpReceiverOptionsConverter.java:
--------------------------------------------------------------------------------
1 | package io.vertx.amqp;
2 |
3 | import io.vertx.core.json.JsonObject;
4 | import io.vertx.core.json.JsonArray;
5 | import java.time.Instant;
6 | import java.time.format.DateTimeFormatter;
7 |
8 | /**
9 | * Converter and mapper for {@link io.vertx.amqp.AmqpReceiverOptions}.
10 | * NOTE: This class has been automatically generated from the {@link io.vertx.amqp.AmqpReceiverOptions} original class using Vert.x codegen.
11 | */
12 | public class AmqpReceiverOptionsConverter {
13 |
14 | static void fromJson(Iterable> json, AmqpReceiverOptions obj) {
15 | for (java.util.Map.Entry member : json) {
16 | switch (member.getKey()) {
17 | case "linkName":
18 | if (member.getValue() instanceof String) {
19 | obj.setLinkName((String)member.getValue());
20 | }
21 | break;
22 | case "dynamic":
23 | if (member.getValue() instanceof Boolean) {
24 | obj.setDynamic((Boolean)member.getValue());
25 | }
26 | break;
27 | case "qos":
28 | if (member.getValue() instanceof String) {
29 | obj.setQos((String)member.getValue());
30 | }
31 | break;
32 | case "capabilities":
33 | if (member.getValue() instanceof JsonArray) {
34 | java.util.ArrayList list = new java.util.ArrayList<>();
35 | ((Iterable