The Aliyun LOG Java Producer is an easy-to-use, highly configurable Java library that helps you send data to Aliyun Log Service. It designed for Java applications which running in big data and high concurrency scenarios.
- Thread safety - all methods exposed by the producer are thread-safe.
- Asynchronous - a call to the send method usually returns immediately and does not wait for the data to be sent or a response to be received from the server.
- Automatic retry - it provides an automatic and configurable retry mechanism for retriable exception.
- Traceability - the caller can not only obtain the information about whether the current data has been sent successfully, but also the attempts information related to the data through callback or future.
- Context restore - the logs generated by the same producer are in the same context, and the relevant logs before and after a certain log can be viewed at the server side.
- Graceful shutdown - when the close method falls back, it ensures that all data cached by producer can be processed and the caller can be notified accordingly.
The following list represents some of the major advantages to using the producer library to send data to log service.
The producer library can help build high-performance producer application. To achieve the throughput needed, producers must implement complicated logic, such as batching or multithreading, in addition to retry logic. The producer library performs all of these tasks for you.
If the available memory is sufficient, the producer will buffer the data before sending them to log service, it does not force the caller application to block and wait for a confirmation that the data has arrived at the server before continuing execution. The caller can get the result of data transmission through the returned future object or the registerd callback.
The size of memory used by the producer can be controlled by parameters as well as the number of threads used to perform data sending tasks. This can avoid unrestricted resource consumption by producer on the one hand, and allows you to balance resource consumption and write throughput according to the actual situation on the other.
Add this dependency to your project's POM:
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>aliyun-log-producer</artifactId>
<version>0.3.23</version>
</dependency>
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>aliyun-log</artifactId>
<version>0.6.116</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
jar-with-dependency version, can resolve dependent version conflicts
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>aliyun-log</artifactId>
<version>0.6.116</version>
<classifier>jar-with-dependencies</classifier>
</dependency>
compile 'com.aliyun.openservices:aliyun-log-producer:0.3.23'
compile 'com.aliyun.openservices:aliyun-log:0.6.116'
compile 'com.google.protobuf:protobuf-java:2.5.0'
If you use the subaccount AK, make sure that the subaccount has write permissions for the target project and logStore, please refer to RAM.
Action | Resource |
---|---|
log:PostLogStoreLogs | acs:log:${regionName}:${projectOwnerAliUid}:project/${projectName}/logstore/${logstoreName} |
https://github.com/aliyun/aliyun-log-producer-sample
If you have further questions please open a GitHub Issue, or sumbit a ticket.