...
- Initialize the data publisher as follows.
AgentHolder. setConfigPath ( getDataAgentConfigPath ());
DataPublisher dataPublisher = new DataPublisher(url, username, password);
Generate the stream ID for the stream from which you are going to publish the event as follows.
String streamId = DataBridgeCommonsUtils.generateStreamId(HTTPD_LOG_STREAM, VERSION ;
- Publish the events using any of the following methods.
In the following configuration, the published event is blocked being called until the event is put into a disruptor. If the disruptor is full it will wait until there is a free space.
Code Block language java Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{"external"}, null, new Object[]{aLog}); dataPublisher.publish(event);
Try publish as shown in the following configuration, is a non-blocking publishing. If there is a space available in the disruptor, it will try to insert the event. However, if the disruptor is full, the event is returned back immediately without waiting.
Code Block language java Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{"external"}, null, new Object[]{aLog}); dataPublisher.tryPublish(event);
Try publish as shown in the following configuration, is a non-blocking publishing with timeout in mili seconds. if there is a space available in the disruptor it will try to insert the event, but if the disruptor is full it will wait for the specified amount of time, and if the timeout is reached the event is returned back.
Code Block language java Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{"external"}, null, new Object[]{aLog}); dataPublisher.tryPublish(event, 100);
Tip When you use the
tryPublish
API, it is important to check the value it returns. If it returnsfalse
(i.e indicating that the event was not sent), you should slow down the process of sending it requests in order to avoid overusing the CPU resources and blocking them for other operations. In order to do this, use the sleep option or similar.
Info |
---|
For more information on the usage of data publishers, see the sample in the |