@@ -16,67 +16,29 @@ with sharding via [vshard](https://github.com/tarantool/vshard).
16
16
17
17
## Quickstart
18
18
19
- 1 . Set up your [ Cartridge cluster] ( https://tarantool.io/cartridge ) . Use an existing Cartridge application or create
20
- a new one from the available [ examples] ( https://github.com/tarantool/examples ) .
21
-
22
- 2 . Add the [ tarantool/crud] ( https://github.com/tarantool/crud ) and [ tarantool/ddl] ( https://github.com/tarantool/ddl )
23
- modules to the dependencies in the [ ` rockspec ` ] ( https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_dev/#creating-a-project )
24
- file of your application.
25
-
26
- 3 . Add the following lines into any [ storage role] ( https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_dev/#cluster-roles )
27
- enabled on all storage instances in your cluster. The lines go into role API declaration section; in other words, into the returned table
28
-
29
- ``` lua
30
- return {
31
- role_name = ' app.roles.api_storage' ,
32
- init = init ,
33
- ...
34
- get_schema = require (' ddl' ).get_schema ,
35
- ...
36
- dependencies = {
37
- ' cartridge.roles.crud-storage'
38
- }
39
- }
40
- ```
41
-
42
- 4 . Add the following lines into any [ router role] ( https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_dev/#cluster-roles )
43
- enabled on all router instances in your cluster to which the driver will be connected to:
44
-
45
- ``` lua
46
- ...
19
+ Example of single instance Tarantool application and java app connected using cartridge-java.
47
20
48
- -- Add the following variables
49
- local cartridge_pool = require (' cartridge.pool' )
50
- local cartridge_rpc = require (' cartridge.rpc' )
21
+ The easiest way to start experimenting with cartridge-java and single instance tarantool app is to use
22
+ [ single instance test] ( /src/test/java/io/tarantool/driver/integration/SingleInstanceExampleTest.java ) .
23
+ You can set breakpoints and run it in debug mode.
24
+ Testcontainers will start [ single instance tarantool application] ( src/test/resources/single-instance.lua ) for you.
25
+ So you will be able to manipulate data in Tarantool in real life through java expressions or Tarantool console.
51
26
52
- ...
53
-
54
- -- Add the following function
55
- local function get_schema ()
56
- for _ , instance_uri in pairs (cartridge_rpc .get_candidates (' app.roles.api_storage' , { leader_only = true })) do
57
- return cartridge_rpc .call (' app.roles.api_storage' , ' get_schema' , nil , { uri = instance_uri })
58
- end
59
- end
60
-
61
- ...
62
-
63
- local function init (opts )
64
- ...
65
- rawset (_G , ' ddl' , { get_schema = get_schema }) -- Add this line
66
- ...
67
- end
27
+ If you want to start tarantool application manually all you need is to run this file in tarantool
28
+ ``` bash
29
+ tarantool src/test/resources/single-instance.lua
68
30
```
69
31
70
- 5 . Check that at least one role enabled on the storage instances depends on the [ ` crud-storage ` ] ( https://github.com/tarantool/crud#api )
71
- role from the ` tarantool/crud ` module and at least one role enabled on the router instances the driver will be connected
72
- to depends on the [ ` crud-router ` ] ( https://github.com/tarantool/crud#api ) role.
32
+ Example of TarantoolClient set up
33
+ https://github.com/tarantool/cartridge-java/blob/master/src/test/java/io/tarantool/driver/integration/SingleInstanceExampleTest.java#L49-L58
73
34
74
- 6 . Start your Cartridge cluster. You may use [ ` cartridge start ` ] ( https://www.tarantool.io/en/doc/latest/book/cartridge/cartridge_cli/ )
75
- for starting it manually or the [ Testcontainers for Tarantool] ( https://github.com/tarantool/cartridge-java-testcontainers )
76
- library for starting it automatically in tests.
35
+ Example of client API usage
36
+ https://github.com/tarantool/cartridge-java/blob/master/src/test/java/io/tarantool/driver/integration/SingleInstanceExampleTest.java#L62-L74
77
37
78
- 7 . Add the following dependency into your project:
38
+ You can read more about Cartridge applications in its [ documentation] ( https://www.tarantool.io/ru/doc/latest/how-to/getting_started_cartridge/ ) .
39
+ Also look at available Cartridge application [ examples] ( https://github.com/tarantool/examples ) .
79
40
41
+ If you use this code in another project don't forget to add ` cartridge-driver ` dependency:
80
42
``` xml
81
43
<dependency >
82
44
<groupId >io.tarantool</groupId >
@@ -85,33 +47,6 @@ library for starting it automatically in tests.
85
47
</dependency >
86
48
```
87
49
88
- 8 . Create a new ` TarantoolClient ` instance:
89
-
90
- ``` java
91
- TarantoolClient<TarantoolTuple , TarantoolResult<TarantoolTuple > > setupClient() {
92
- return TarantoolClientFactory . createClient()
93
- // If any addresses or an address provider are not specified, the default host 127.0.0.1 and port 3301 are used
94
- .withAddress(" 123.123.123.1" )
95
- // For connecting to a Cartridge application, use the value of cluster_cookie parameter in the init.lua file
96
- .withCredentials(" admin" , " secret-cluster-cookie" )
97
- // you may also specify more client settings, such as:
98
- // timeouts, number of connections, custom MessagePack entities to Java objects mapping, etc.
99
- .build();
100
- }
101
- ```
102
-
103
- 9 . Use the API provided by the Tarantool client, for example:
104
-
105
- ``` java
106
- TarantoolTupleFactory tupleFactory = new DefaultTarantoolTupleFactory (mapperFactory. defaultComplexTypesMapper());
107
- TarantoolSpaceOperations<TarantoolTuple , TarantoolResult<TarantoolTuple > > profileSpace = client. space(" profile" );
108
-
109
- List<Object > values = Arrays . asList(123 , null , " Jane Doe" , 18 , 999 );
110
- TarantoolTuple tarantoolTuple = tupleFactory. create(values);
111
-
112
- TarantoolResult<TarantoolTuple > insertTuples = profileSpace. insert(tarantoolTuple). get();
113
- ```
114
-
115
50
### Cluster Tarantool client
116
51
117
52
Connects to multiple Tarantool nodes, usually Tarantool Cartridge routers. Supports multiple connections to one node.
@@ -122,7 +57,7 @@ connections are open to a single host (using the `connections` option in the con
122
57
closed, all connections to that host are gracefully closed and re-established.
123
58
124
59
You may set up automatic retrieving of the list of cluster nodes available for connection (aka discovery). Discovery
125
- provider variants with a HTTP endpoint and a stored function in Tarantool are available out-of-the-box. You may use
60
+ provider variants with an HTTP endpoint and a stored function in Tarantool are available out-of-the-box. You may use
126
61
these variants or create your own discovery provider implementation. In real environments with high availability
127
62
requirements it is recommended to use an external configuration provider (like etcd), DNS or a balancing proxy for
128
63
connecting to the Tarantool server.
0 commit comments