-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce options to configure the creation of an event-bus consumer …
…and deprecate message consumer max buffered message upper bound setter. Motivation: The event-bus message consumer has a dynamic max buffered messages upper bound. This dynamic bound makes difficult to implement the message flow and requires a custom implementation. Instead this should be configured when the consumer is created. Changes: Introduce MessageConsumerOptions that provides all the necessary details to create a consumer (address, localOnly, maxBufferedMessages). Consumer setMaxBufferedMessages is deprecated in favour of using options.
- Loading branch information
Showing
7 changed files
with
201 additions
and
10 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/main/generated/io/vertx/core/eventbus/MessageConsumerOptionsConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package io.vertx.core.eventbus; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import io.vertx.core.json.JsonArray; | ||
import io.vertx.core.json.impl.JsonUtil; | ||
import java.time.Instant; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Base64; | ||
|
||
/** | ||
* Converter and mapper for {@link io.vertx.core.eventbus.MessageConsumerOptions}. | ||
* NOTE: This class has been automatically generated from the {@link io.vertx.core.eventbus.MessageConsumerOptions} original class using Vert.x codegen. | ||
*/ | ||
public class MessageConsumerOptionsConverter { | ||
|
||
|
||
private static final Base64.Decoder BASE64_DECODER = JsonUtil.BASE64_DECODER; | ||
private static final Base64.Encoder BASE64_ENCODER = JsonUtil.BASE64_ENCODER; | ||
|
||
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, MessageConsumerOptions obj) { | ||
for (java.util.Map.Entry<String, Object> member : json) { | ||
switch (member.getKey()) { | ||
case "address": | ||
if (member.getValue() instanceof String) { | ||
obj.setAddress((String)member.getValue()); | ||
} | ||
break; | ||
case "localOnly": | ||
if (member.getValue() instanceof Boolean) { | ||
obj.setLocalOnly((Boolean)member.getValue()); | ||
} | ||
break; | ||
case "maxBufferedMessages": | ||
if (member.getValue() instanceof Number) { | ||
obj.setMaxBufferedMessages(((Number)member.getValue()).intValue()); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
static void toJson(MessageConsumerOptions obj, JsonObject json) { | ||
toJson(obj, json.getMap()); | ||
} | ||
|
||
static void toJson(MessageConsumerOptions obj, java.util.Map<String, Object> json) { | ||
if (obj.getAddress() != null) { | ||
json.put("address", obj.getAddress()); | ||
} | ||
json.put("localOnly", obj.isLocalOnly()); | ||
json.put("maxBufferedMessages", obj.getMaxBufferedMessages()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/main/java/io/vertx/core/eventbus/MessageConsumerOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package io.vertx.core.eventbus; | ||
|
||
import io.vertx.codegen.annotations.DataObject; | ||
import io.vertx.codegen.json.annotations.JsonGen; | ||
import io.vertx.core.impl.Arguments; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
@DataObject | ||
@JsonGen(publicConverter = false) | ||
public class MessageConsumerOptions { | ||
|
||
public static final int DEFAULT_MAX_BUFFERED_MESSAGES = 1000; | ||
public static final boolean DEFAULT_LOCAL_ONLY = false; | ||
|
||
private String address; | ||
private boolean localOnly; | ||
private int maxBufferedMessages; | ||
|
||
public MessageConsumerOptions() { | ||
maxBufferedMessages = DEFAULT_MAX_BUFFERED_MESSAGES; | ||
localOnly = DEFAULT_LOCAL_ONLY; | ||
} | ||
|
||
public MessageConsumerOptions(MessageConsumerOptions options) { | ||
this(); | ||
maxBufferedMessages = options.getMaxBufferedMessages(); | ||
localOnly = options.isLocalOnly(); | ||
address = options.getAddress(); | ||
} | ||
|
||
public MessageConsumerOptions(JsonObject json) { | ||
this(); | ||
MessageConsumerOptionsConverter.fromJson(json, this); | ||
} | ||
|
||
/** | ||
* @return the address the event-bus will register the consumer at | ||
*/ | ||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
/** | ||
* Set the address the event-bus will register the consumer at. | ||
* | ||
* @param address the consumer address | ||
* @return this options | ||
*/ | ||
public MessageConsumerOptions setAddress(String address) { | ||
this.address = address; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return whether the consumer is local only | ||
*/ | ||
public boolean isLocalOnly() { | ||
return localOnly; | ||
} | ||
|
||
/** | ||
* Set whether the consumer is local only. | ||
* | ||
* @param localOnly whether the consumer is local only | ||
* @return this options | ||
*/ | ||
public MessageConsumerOptions setLocalOnly(boolean localOnly) { | ||
this.localOnly = localOnly; | ||
return this; | ||
} | ||
|
||
/** | ||
* @return the maximum number of messages that can be buffered when this stream is paused | ||
*/ | ||
public int getMaxBufferedMessages() { | ||
return maxBufferedMessages; | ||
} | ||
|
||
/** | ||
* Set the number of messages this registration will buffer when this stream is paused. The default | ||
* value is <code>1000</code>. | ||
* <p> | ||
* When a new value is set, buffered messages may be discarded to reach the new value. The most recent | ||
* messages will be kept. | ||
* | ||
* @param maxBufferedMessages the maximum number of messages that can be buffered | ||
* @return this options | ||
*/ | ||
public MessageConsumerOptions setMaxBufferedMessages(int maxBufferedMessages) { | ||
Arguments.require(maxBufferedMessages >= 0, "Max buffered messages cannot be negative"); | ||
this.maxBufferedMessages = maxBufferedMessages; | ||
return this; | ||
} | ||
|
||
public JsonObject toJson() { | ||
JsonObject json = new JsonObject(); | ||
MessageConsumerOptionsConverter.toJson(this, json); | ||
return json; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters