@@ -285,119 +285,9 @@ mvn compile && mvn package && java -jar target/spawn-java-demo-1.0-SNAPSHOT.jar
285
285
```
286
286
287
287
But of course you will need to locally run the Elixir proxy which will actually provide all the functionality for your Java application.
288
- One way to do this is to create a docker-compose file containing all the services that your application depends on,
289
- in this case, in addition to the Spawn proxy, it also has a database and possibly a nats broker if you want access to
290
- more advanced Spawn features.
291
-
292
- ``` docker-compose
293
- version: "3.8"
294
- services:
295
- mariadb:
296
- image: mariadb
297
- environment:
298
- MYSQL_ROOT_PASSWORD: admin
299
- MYSQL_DATABASE: eigr-functions-db
300
- MYSQL_USER: admin
301
- MYSQL_PASSWORD: admin
302
- volumes:
303
- - mariadb:/var/lib/mysql
304
- ports:
305
- - "3307:3306"
306
- nats:
307
- image: nats:0.8.0
308
- entrypoint: "/gnatsd -DV"
309
- ports:
310
- - "8222:8222"
311
- - "4222:4222"
312
- spawn-proxy:
313
- build:
314
- context: https://github.com/eigr/spawn.git#main
315
- dockerfile: ./Dockerfile-proxy
316
- restart: always
317
- network_mode: "host"
318
- environment:
319
- SPAWN_USE_INTERNAL_NATS: "true"
320
- SPAWN_PUBSUB_ADAPTER: nats
321
- SPAWN_STATESTORE_KEY: 3Jnb0hZiHIzHTOih7t2cTEPEpY98Tu1wvQkPfq/XwqE=
322
- PROXY_APP_NAME: spawn
323
- PROXY_CLUSTER_STRATEGY: gossip
324
- PROXY_DATABASE_PORT: 3307
325
- PROXY_DATABASE_TYPE: mariadb
326
- PROXY_HTTP_PORT: 9003
327
- USER_FUNCTION_PORT: 8091
328
- depends_on:
329
- - mariadb
330
- - nats
331
- networks:
332
- mysql-compose-network:
333
- driver: bridge
334
- volumes:
335
- mariadb:
336
288
337
- ```
338
-
339
- > ** _ NOTE:_ ** Or just use the [ Spawn CLI] ( https://github.com/eigr/spawn?tab=readme-ov-file#getting-started-with-spawn ) to take care of the development environment for you.
340
-
341
- You may also want your Actors to be initialized with some dependent objects similarly to how you would use the
342
- dependency injection pattern.
343
- In this case, it is enough to declare a constructor that receives a single argument for its actor.
344
-
345
- ``` java
346
- package io.eigr.spawn.java.demo ;
347
-
348
- import io.eigr.spawn.api.actors.ActorContext ;
349
- import io.eigr.spawn.api.actors.StatefulActor ;
350
- import io.eigr.spawn.api.actors.Value ;
351
- import io.eigr.spawn.api.actors.behaviors.ActorBehavior ;
352
- import io.eigr.spawn.api.actors.behaviors.BehaviorCtx ;
353
- import io.eigr.spawn.api.actors.behaviors.NamedActorBehavior ;
354
- import io.eigr.spawn.internal.ActionBindings ;
355
- import io.eigr.spawn.java.demo.domain.Actor.Reply ;
356
- import io.eigr.spawn.java.demo.domain.Actor.Request ;
357
- import io.eigr.spawn.java.demo.domain.Actor.State ;
358
-
359
- import static io.eigr.spawn.api.actors.behaviors.ActorBehavior.action ;
360
- import static io.eigr.spawn.api.actors.behaviors.ActorBehavior.name ;
361
- public final class JoeActor implements StatefulActor<State > {
362
-
363
- private String defaultMessage;
364
-
365
- @Override
366
- public ActorBehavior configure (BehaviorCtx context ) {
367
- defaultMessage = context. getInjector(). getInstance(String . class);
368
- return new NamedActorBehavior (
369
- name(" JoeActor" ),
370
- action(" SetLanguage" , ActionBindings . of(Request . class, this :: setLanguage))
371
- );
372
- }
373
-
374
- // ...
375
- }
376
- ```
377
-
378
- Then you also need to register your Actor using injector :
379
-
380
- ``` java
381
- package io.eigr.spawn.java.demo ;
382
-
383
- import io.eigr.spawn.api.Spawn ;
384
-
385
- import java.util.HashMap ;
386
- import java.util.Map ;
387
-
388
- public class App {
389
- public static void main (String [] args ) {
390
- DependencyInjector injector = SimpleDependencyInjector . createInjector();
391
- injector. bind(String . class, " Hello with Constructor" );
392
-
393
- Spawn spawnSystem = new Spawn .SpawnSystem ()
394
- .create(" spawn-system" , injector)
395
- .withActor(Joe . class)
396
- .build();
397
-
398
- spawnSystem. start();
399
- }
400
- }
289
+ ``` shell
290
+ spawn dev run -p src/main/proto -s spawn-system -W
401
291
```
402
292
403
293
Spawn is based on kubernetes and containers, so you will need to generate a docker container for your application.
@@ -416,6 +306,7 @@ Add the following lines to your plugin's section in pom.xml file:
416
306
</configuration >
417
307
</plugin >
418
308
```
309
+
419
310
finally you will be able to create your container by running the following command in the root of your project:
420
311
421
312
``` shell
0 commit comments