Skip to content

feign-based http client for working with NEM blockchain

License

Notifications You must be signed in to change notification settings

rosklyar/nem-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lightweight java library to integrate with NEM blockchain

Uses:

Usage

1. Import library as maven dependency

<dependency>
    <groupId>com.github.rosklyar</groupId>
    <artifactId>nem-library</artifactId>
    <version>1.1</version>
</dependency>

2. Configure library using archaius

I used static config instance in tests to setup configuration:
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:

-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:

3. Create client instance using DefaultNemClientFactory

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");
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:

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