-
Notifications
You must be signed in to change notification settings - Fork 14
Add async as config option #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ac44712
ef090c8
7b2f968
882ff02
7c1bc75
2fb1f80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,9 @@ public class Pulsar implements Output { | |
private static final PluginConfigSpec<String> CONFIG_AUTH_PLUGIN_PARAMS_STRING = | ||
PluginConfigSpec.stringSetting("auth_plugin_params_String",""); | ||
|
||
private static final PluginConfigSpec<Boolean> CONFIG_ENABLE_ASYNC = | ||
PluginConfigSpec.booleanSetting("enable_async",false); | ||
|
||
private final CountDownLatch done = new CountDownLatch(1); | ||
|
||
private final String producerName; | ||
|
@@ -125,6 +128,9 @@ public class Pulsar implements Output { | |
//Token | ||
private final boolean enableToken; | ||
|
||
// Sends messages async if set, otherwise sync | ||
private final boolean enableAsync; | ||
|
||
// TODO: batchingMaxPublishDelay milliseconds | ||
|
||
// TODO: sendTimeoutMs milliseconds 30000 | ||
|
@@ -148,6 +154,7 @@ public Pulsar(final String id, final Configuration configuration, final Context | |
|
||
enableTls = configuration.get(CONFIG_ENABLE_TLS); | ||
enableToken = configuration.get(CONFIG_ENABLE_TOKEN); | ||
enableAsync = configuration.get(CONFIG_ENABLE_ASYNC); | ||
|
||
try { | ||
if(enableTls && enableToken){ | ||
|
@@ -222,15 +229,25 @@ public void output(final Collection<Event> events) { | |
codec.encode(event, baos); | ||
String s = baos.toString(); | ||
logger.debug("topic is {}, message is {}", eventTopic, s); | ||
getProducer(eventTopic).newMessage() | ||
.value(s.getBytes()) | ||
.sendAsync(); | ||
send(eventTopic, s); | ||
} catch (Exception e) { | ||
logger.error("fail to send message", e); | ||
} | ||
} | ||
} | ||
|
||
private void send(String topic, String s){ | ||
if (enableAsync){ | ||
getProducer(topic).newMessage() | ||
.value(s.getBytes()) | ||
.sendAsync(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need to add a callback to print a log when failing to publish messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This send function is only called inside a try/catch, where it logs "fail to send message" with the exception. See line 225-235. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It won't catch the exception thrown from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay.. Am I reading this right? CompletableFuture.exceptionally description:
This doesn't throw a custom Exception that inherits from the class Exception as usual? I don't think I understand what this is describing. I'm trying to decipher it, but does it mean that it returns the function that triggered an Exception rather than actually throwing the Exception. In that case I guess I couldn't try/catch? Or does it mean that I am supposed to just provide a function that is throwable, so when CompletableFuture throws, it triggers my function with where it failed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the late reply. The Therefore if there are any exceptions thrown in the send operation, the function
That's correct. However, you still need to use try/catch here, because we couldn't guarantee that this code won't throw the exception:
|
||
}else { | ||
getProducer(topic).newMessage() | ||
.value(s.getBytes()) | ||
.send(); | ||
} | ||
} | ||
|
||
private org.apache.pulsar.client.api.Producer<byte[]> getProducer(String topic) throws PulsarClientException { | ||
|
||
if(producerMap.containsKey(topic)){ | ||
|
Uh oh!
There was an error while loading. Please reload this page.