https://github.com/rosklyar/nem-library
feign-based http client for working with NEM blockchain
https://github.com/rosklyar/nem-library
archaius archaius-configuration circuit-breaker hystrix java kotlin nem nem-blockchain ribbon scala
Last synced: 6 months ago
JSON representation
feign-based http client for working with NEM blockchain
- Host: GitHub
- URL: https://github.com/rosklyar/nem-library
- Owner: rosklyar
- License: mit
- Created: 2018-02-24T10:19:54.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-27T12:37:58.000Z (over 8 years ago)
- Last Synced: 2025-07-07T04:52:43.056Z (about 1 year ago)
- Topics: archaius, archaius-configuration, circuit-breaker, hystrix, java, kotlin, nem, nem-blockchain, ribbon, scala
- Language: Java
- Homepage:
- Size: 169 KB
- Stars: 6
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Lightweight java library to integrate with NEM blockchain
Uses:
- feign(https://github.com/OpenFeign/feign) to make http calls to NIS(based on docs from https://nemproject.github.io/)
- hystrix(https://github.com/Netflix/Hystrix) to implement circuit breaker
- ribbon(https://github.com/Netflix/ribbon) to implement load balancing
- archaius(https://github.com/Netflix/archaius) to configure library
Usage
1. Import library as maven dependency
```xml
com.github.rosklyar
nem-library
1.1
```
2. Configure library using archaius
I used static config instance in tests to setup configuration:
```java
ConfigurationManager.getConfigInstance().setProperty("transactionApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("accountApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("mosaicApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("nodeApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("statusApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("blockchainApi.ribbon.listOfServers", "153.122.112.137:7890");
ConfigurationManager.getConfigInstance().setProperty("hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds", 20000);
```
You can also use separate file(or any other configuration source archaius supports - https://github.com/Netflix/archaius/wiki) to setup configuration. Add this to your application start up script to import configuration from file:
```bash
-Darchaius.configurationSource.additionalUrls=file:///apps/myapp/nem-library.properties
```
Example of properties file needed for MAIN network see at src/test/resources/nem-library.properties.
You also can configure hystrix(circuit breaker) and ribbon(load balancing) with archaius configuration. For details see projects documentation pages:
- https://github.com/Netflix/Hystrix/wiki/Configuration
- https://github.com/Netflix/ribbon/wiki/Programmers-Guide
3. Create client instance using DefaultNemClientFactory
```java
AccountClient accountClient = new DefaultNemClientFactory().createAccountClient("accountApi");
BlockchainClient blockchainClient = new DefaultNemClientFactory().createBlockchainClient("blockchainApi");
MosaicClient mosaicClient = new DefaultNemClientFactory().createMosaicClient("mosaicApi");
NodeClient nodeClient = new DefaultNemClientFactory().createNodeClient("nodeApi");
StatusClient statusClient = new DefaultNemClientFactory().createStatusClient("statusApi");
```
```java
DefaultNemClientFactory factory = new DefaultNemClientFactory();
transactionClient = factory.createTransactionClient(
"transactionApi",
DefaultNemClientFactory.MAIN,
mosaicClient,
accountClient,
nodeClient
);
```
Simple clients
You can create needed clients much more simple using just url of desired NIS:
```java
AccountClient accountClient = new DefaultNemClientFactory().simpleAccountClient("http://153.122.112.137:7890");
BlockchainClient blockchainClient = new DefaultNemClientFactory().simpleBlockchainClient("http://153.122.112.137:7890");
MosaicClient mosaicClient = new DefaultNemClientFactory().simpleMosaicClient("http://153.122.112.137:7890");
NodeClient nodeClient = new DefaultNemClientFactory().simpleNodeClient("http://153.122.112.137:7890");
StatusClient statusClient = new DefaultNemClientFactory().simpleStatusClient("http://153.122.112.137:7890");
TransactionClient simpleTransactionClient = new DefaultNemClientFactory().simpleTransactionClient("http://153.122.112.137:7890", DefaultNemClientFactory.MAIN);
```
Example of usage you can see in tests package src/test/java/com/github/rosklyar/client
You can support project if you want
XEM: NALNZB-Q4JJP2-PYAS6I-4KWTLT-367SJJ-RKXX6I-WUQR
ETH: 0x310535217083ba1073b4CB57B9DDc4dFF6176961
XLM: GBBLG6YGAHVFNQJ6ZE7MCJENRYLHY2G475PRQKRWF46YZQ7Q3MES4NRD
Copyright (c) 2018