﻿1
00:00:04,809 --> 00:00:07,878
welcome to section 5 working with akka

2
00:00:07,878 --> 00:00:10,730
cluster in the previous section we

3
00:00:10,730 --> 00:00:12,888
worked with akka persistence we

4
00:00:12,888 --> 00:00:14,960
discussed akka persistence architecture

5
00:00:14,960 --> 00:00:17,660
and implemented a persistent actor then

6
00:00:17,660 --> 00:00:19,969
we implemented persistence FSM and

7
00:00:19,969 --> 00:00:23,439
finally discussed persistence query in

8
00:00:23,439 --> 00:00:25,939
this section we will work with other

9
00:00:25,939 --> 00:00:28,070
features in occur such as a quorum oat

10
00:00:28,070 --> 00:00:30,920
and akka cluster first we will introduce

11
00:00:30,920 --> 00:00:33,289
occur remoting and implement a remote

12
00:00:33,289 --> 00:00:35,988
actor then we will introduce a cluster

13
00:00:35,988 --> 00:00:38,058
and implement some concepts on it such

14
00:00:38,058 --> 00:00:40,488
as load balancer cluster sharding and

15
00:00:40,488 --> 00:00:44,600
cluster singleton let's starts with akka

16
00:00:44,600 --> 00:00:47,750
remoting in this first video in this

17
00:00:47,750 --> 00:00:49,808
video we will take a look at

18
00:00:49,808 --> 00:00:52,939
introduction to a career Moton preparing

19
00:00:52,939 --> 00:00:54,859
your actor system for occur remoting

20
00:00:54,859 --> 00:00:57,710
starting a remote actor let's get

21
00:00:57,710 --> 00:01:00,798
started in all the previous sections

22
00:01:00,798 --> 00:01:02,988
until now we have worked on examples

23
00:01:02,988 --> 00:01:04,849
that have one actor system running on a

24
00:01:04,849 --> 00:01:07,640
local machine but in real life your

25
00:01:07,640 --> 00:01:09,560
application will pertain to parts and

26
00:01:09,560 --> 00:01:12,010
every part may run on a different node

27
00:01:12,010 --> 00:01:14,359
everything in akka is designed to work

28
00:01:14,359 --> 00:01:16,519
in a distributed setting and the a

29
00:01:16,519 --> 00:01:18,349
khadeem has done a great job protecting

30
00:01:18,349 --> 00:01:20,689
the application from all the complexity

31
00:01:20,689 --> 00:01:22,609
that revolves around the remoting system

32
00:01:22,609 --> 00:01:26,120
now let's define a kareem outing akka

33
00:01:26,120 --> 00:01:28,489
remoting is a communication module to

34
00:01:28,489 --> 00:01:30,379
connect actor systems in a peer-to-peer

35
00:01:30,379 --> 00:01:32,989
fashion and it is the foundation for a

36
00:01:32,989 --> 00:01:35,870
clustering in a production setting it is

37
00:01:35,870 --> 00:01:37,790
recommended to rely on akka cluster

38
00:01:37,790 --> 00:01:40,280
directly instead of remoting however

39
00:01:40,280 --> 00:01:42,469
let's see how it works before we jumped

40
00:01:42,469 --> 00:01:44,540
the cluster let's start playing with

41
00:01:44,540 --> 00:01:47,629
akka remoting akka remoting like Acker

42
00:01:47,629 --> 00:01:50,478
persistence is a separate dependency so

43
00:01:50,478 --> 00:01:52,129
we should be adding this dependency in

44
00:01:52,129 --> 00:01:55,579
our application now to enable ack

45
00:01:55,579 --> 00:01:57,200
remoting we should update our

46
00:01:57,200 --> 00:01:59,810
application confiar we should at least

47
00:01:59,810 --> 00:02:01,280
add these four things in our

48
00:02:01,280 --> 00:02:04,280
configuration first we should change the

49
00:02:04,280 --> 00:02:07,250
provider from a corrector local actor

50
00:02:07,250 --> 00:02:10,699
ref provider to a Kodomo top remote

51
00:02:10,699 --> 00:02:13,009
actor ref provider

52
00:02:13,009 --> 00:02:16,280
second we add a tcp on the enabled

53
00:02:16,280 --> 00:02:19,759
transports list third we define a

54
00:02:19,759 --> 00:02:22,009
hostname let's say it's our localhost

55
00:02:22,009 --> 00:02:26,150
and finally we define a port let's say

56
00:02:26,150 --> 00:02:29,209
it is two five five to each actor system

57
00:02:29,209 --> 00:02:31,219
needs to have either a unique port if

58
00:02:31,219 --> 00:02:33,439
shared on the same host or they can use

59
00:02:33,439 --> 00:02:35,360
the same port if started on multiple

60
00:02:35,360 --> 00:02:37,370
nodes in the cluster now our application

61
00:02:37,370 --> 00:02:39,969
is ready great

62
00:02:39,969 --> 00:02:42,590
here is a worker actor that handles work

63
00:02:42,590 --> 00:02:44,840
messages and when it receives a work

64
00:02:44,840 --> 00:02:50,120
message it just prints that message now

65
00:02:50,120 --> 00:02:52,699
let's create our actor system using our

66
00:02:52,699 --> 00:02:55,908
configuration in the member service

67
00:02:55,908 --> 00:02:57,500
object we will load our configuration

68
00:02:57,500 --> 00:03:02,329
and then create our system then let's

69
00:03:02,329 --> 00:03:04,219
create an instance of the worker actor

70
00:03:04,219 --> 00:03:06,289
this code is similar to the code from

71
00:03:06,289 --> 00:03:08,419
the previous sections but the only

72
00:03:08,419 --> 00:03:10,370
difference is that this actor system is

73
00:03:10,370 --> 00:03:14,030
a remote actor system now let's run this

74
00:03:14,030 --> 00:03:16,689
actor system

75
00:03:16,689 --> 00:03:20,210
great actor system is running and here

76
00:03:20,210 --> 00:03:23,060
we have the path for our worker actor we

77
00:03:23,060 --> 00:03:24,889
have two types of remote interactions

78
00:03:24,889 --> 00:03:28,789
lookup and creations lookup is used to

79
00:03:28,789 --> 00:03:30,889
look up an actor on a remote node with

80
00:03:30,889 --> 00:03:33,590
actor selection creation is used to

81
00:03:33,590 --> 00:03:35,599
create an actor on a remote node with

82
00:03:35,599 --> 00:03:38,539
actor of let's start with the lookup

83
00:03:38,539 --> 00:03:41,000
example first we'll add the

84
00:03:41,000 --> 00:03:43,039
configuration for member service lookup

85
00:03:43,039 --> 00:03:45,229
actor system it is similar to our

86
00:03:45,229 --> 00:03:47,000
previous configuration but we will

87
00:03:47,000 --> 00:03:49,939
change the port now in the member

88
00:03:49,939 --> 00:03:52,099
service lookup object we need to start

89
00:03:52,099 --> 00:03:55,129
our actor system first we need to read

90
00:03:55,129 --> 00:04:03,689
our configuration

91
00:04:03,689 --> 00:04:06,090
then we need to send the message to the

92
00:04:06,090 --> 00:04:09,150
worker actor in another actor system we

93
00:04:09,150 --> 00:04:11,969
will use the actor selection method the

94
00:04:11,969 --> 00:04:13,770
pattern of remote actors path like this

95
00:04:13,770 --> 00:04:16,560
it's like a path for normal actor but we

96
00:04:16,560 --> 00:04:19,100
provide the remote system host and port

97
00:04:19,100 --> 00:04:21,540
so let's add the actor selection for the

98
00:04:21,540 --> 00:04:23,879
worker then let's send a message for the

99
00:04:23,879 --> 00:04:27,930
selection actor now let's run the member

100
00:04:27,930 --> 00:04:32,670
services look up actor system now let's

101
00:04:32,670 --> 00:04:36,509
check the first terminal yeah the worker

102
00:04:36,509 --> 00:04:39,990
actor receives our message excellent now

103
00:04:39,990 --> 00:04:42,290
let's try another remote interaction

104
00:04:42,290 --> 00:04:45,180
first let's add our configuration in

105
00:04:45,180 --> 00:04:47,519
this example we will add some extra

106
00:04:47,519 --> 00:04:49,560
configuration to describe the deployment

107
00:04:49,560 --> 00:04:52,439
for the remote worker service here is

108
00:04:52,439 --> 00:04:54,149
the creation of member service creation

109
00:04:54,149 --> 00:04:57,899
it is our new actor system now we will

110
00:04:57,899 --> 00:04:59,759
create a remote worker service actor

111
00:04:59,759 --> 00:05:02,459
using actor off like any normal creation

112
00:05:02,459 --> 00:05:06,029
and then send a message to it now let's

113
00:05:06,029 --> 00:05:09,990
run the third actor system yeah there is

114
00:05:09,990 --> 00:05:12,600
our message let's check our terminal for

115
00:05:12,600 --> 00:05:15,660
the first actor yeah our worker actor

116
00:05:15,660 --> 00:05:18,649
received our message awesome well done

117
00:05:18,649 --> 00:05:21,240
you can check full documentation for

118
00:05:21,240 --> 00:05:29,879
Acker remoting from here

119
00:05:29,879 --> 00:05:30,909
you


