Re: [akka-user] Basic akka - locating actors and their state

2017-05-13 Thread Justin du coeur
While it's not unreasonable to structure the Actor hierarchy like this, I
suspect it's not actually what you want.  It is specifically likely to make
it a hassle to look up Users just by their UserID.

Rather, I would recommend researching Akka Clustering Sharding.  That's
very likely the right way for you to manage your User Actors, because it is
designed precisely for the case where you want to be able to look up (and
create, when necessary) an Actor of a particular type given an ID.  Storing
data in the UserActor makes good sense, especially if you pair this with
Akka Persistence -- that's often the easiest way to set things up.

In all likelihood, you should have a separate Clustering Sharding Region
for Countries as well, if they have their own data.  A Country might well
contain a list of Region IDs, even if those Regions aren't actually Actors.

As for Regions, I'm not sure -- you might want to think about whether
Regions are anything more than an identifier that is used as a handle for
subscribing and broadcasting events.  That is, instead of "look up all the
actors by Region", you might want to instead ask "how do I *broadcast* to
all Users in a Region?", which might be an easier problem to solve.  I
wouldn't bother making Regions an Actor type unto themselves unless there
was some per-Region state you were managing.

On Sat, May 13, 2017 at 6:00 PM, Christian Hessenbruch 
wrote:

> This is a couple of very basic questions concerning akka. I'm totally
> green on akka, so any advice is appreciated.
>
>
> Say that I have an application with thousands of users - not millions.
>
>
> The domain model is a hierarchy where each user is located in a region
> within a country i.e. a country has multiply regions, a region has multiple
> users.
>
>
> I'm thinking of creating the exact same hierarchy in akka. CountryActor
> ->* RegionActor ->* UserActor. The CountryActor could aside from being
> parent, also have functional duties such as collecting newsfeeds,
> calculating statistics, supervising its children etc. Whereas the
> RegionActor is only a parent of UserActors.
>
>
> *Q1: Does it make sense to mimic the domain model this way?*
>
>
> *Q2: Should I store the attributes of each entity in the actor?* This way
> the data would only need to be stored once and the akka system would
> effectively be memory database as well.
>
>
> (pseudo-code)
>
> CountryActor {
>   Name,
>   CountryCode,
>   (children = list of RegionActors handled by akka)
> }
>
> RegionActor {
>   Name,
>   RegionCode,
>   (children = list of UserActors handled by akka)
> }
>
> UserActor {
>   UserId,
>   Firstname,
>   Lastname,
>   Alias,
>   ReceiveRegionalNews,
>   ReceiveCountryNews,
>   ...
> }
>
>
> *Q3: How do I efficiently lookup a user by userId?* I expect the
> child-name of the UserActor will be the userId, but given that I only have
> a userId, I still need to find that correct Country and Region to do a
> getContent().findChild(userId)? Do I need to keep a complete map of all
> userIds and reference to their actor?
>
>
> *Q4: How to locate actors by their state?* Imagine that each user has the
> ability to switch on a RegionalNews attribute, which means that he wants to
> receive news from the RegionalActor. Whenever the RegionalActor want to
> distribute news to all listeners, how does it locate them? Does it keep an
> internal map of the users with the attribute or does it make a broadcast to
> all it's children and then send to all responders?
>
>
> Thanks in advance
>
> --
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: http://doc.akka.io/docs/akka/
> current/additional/faq.html
> >> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to akka-user+unsubscr...@googlegroups.com.
> To post to this group, send email to akka-user@googlegroups.com.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


[akka-user] Basic akka - locating actors and their state

2017-05-13 Thread Christian Hessenbruch


This is a couple of very basic questions concerning akka. I'm totally green 
on akka, so any advice is appreciated.


Say that I have an application with thousands of users - not millions.


The domain model is a hierarchy where each user is located in a region 
within a country i.e. a country has multiply regions, a region has multiple 
users.


I'm thinking of creating the exact same hierarchy in akka. CountryActor ->* 
RegionActor ->* UserActor. The CountryActor could aside from being parent, 
also have functional duties such as collecting newsfeeds, calculating 
statistics, supervising its children etc. Whereas the RegionActor is only a 
parent of UserActors.


*Q1: Does it make sense to mimic the domain model this way?*


*Q2: Should I store the attributes of each entity in the actor?* This way 
the data would only need to be stored once and the akka system would 
effectively be memory database as well.


(pseudo-code)

CountryActor {
  Name,
  CountryCode,
  (children = list of RegionActors handled by akka)
}

RegionActor {
  Name,
  RegionCode,
  (children = list of UserActors handled by akka)
}

UserActor {
  UserId,
  Firstname,
  Lastname,
  Alias,
  ReceiveRegionalNews,
  ReceiveCountryNews,
  ...
}


*Q3: How do I efficiently lookup a user by userId?* I expect the child-name 
of the UserActor will be the userId, but given that I only have a userId, I 
still need to find that correct Country and Region to do a 
getContent().findChild(userId)? Do I need to keep a complete map of all 
userIds and reference to their actor?


*Q4: How to locate actors by their state?* Imagine that each user has the 
ability to switch on a RegionalNews attribute, which means that he wants to 
receive news from the RegionalActor. Whenever the RegionalActor want to 
distribute news to all listeners, how does it locate them? Does it keep an 
internal map of the users with the attribute or does it make a broadcast to 
all it's children and then send to all responders?


Thanks in advance

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] How to map unstructured Json to a case class in Akka-Http

2017-05-13 Thread Konrad Malawski
Please read the docs about json support:
http://doc.akka.io/docs/akka-http/current/scala/http/common/json-support.html

You're likely missing SprayJsonSupport

-- 
Konrad `ktoso` Malawski
Akka  @ Lightbend 

On 13 May 2017 at 10:47:51, vishal.ve...@exadatum.com (
vishal.ve...@exadatum.com) wrote:


I am trying to create the REST service using akka Http and slick . I am
trying to persist the Raw json in the MySql table in string format or BLOB
format whichever can solve my problem.
The point where I am facing issues is Every time I try to store the Json
via akka http routes , It throws an error about json being malformed.

object Models {
  case class Customer(name: String,jsonData:String)
  object ServiceJsonProtoocol extends DefaultJsonProtocol {
implicit val customerProtocol = jsonFormat2(Customer)
  }
}

object AkkaJsonParsing {



  def main(args: Array[String]) {

implicit val actorSystem = ActorSystem("rest-api")

implicit val actorMaterializer = ActorMaterializer()

val list = new ConcurrentLinkedDeque[Customer]()

import ServiceJsonProtoocol.customerProtocol
val route =
  path("customer") {
post {
  entity(as[Customer]) {
customer => complete {
  list.add(customer)
  s"got customer json ${customer.jsonData}"
}
  }
}





Json
{
"name":"test",
   "json":[{"type":"alpha","gross":"alpha"}]

}



Error :Request was rejected with rejection
MalformedRequestContentRejection(Expected String as JsString, but got
[{"type":"alpha","gross":"alpha"}],None)


I tried changing case class jsonData datatype to Byte,Array[Byte] but
nothing helps.
what is the right way to persist whole json?

--
>> Read the docs: http://akka.io/docs/
>> Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html
>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups
"Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Using Akka for Data Synchronization Use Case

2017-05-13 Thread 'Michal Borowiecki' via Akka User List

Hi Santanu,

I'm not sure I know enough about your requirements to advise.

In microservices for each piece of data I'd have only one of the 
services be the "source of truth" for that data and others subscribe to 
events from that microservice.


In your original case, however, it's not clear if there is an "owning" 
side or are both the Intranet and Internet applications meant to be 
symmetrical. If it's the latter then I don't know it's a common enough 
scenario for there to be "reference architecture" but if your data 
volumes aren't huge, I'd start off by looking at CRDTs (akka distributed 
data ).


You also asked if akka can use a message queue and yes, my favourite is 
kafka and akka-stream-kafka 
 is the 
integration library.


Hope that gives you some pointers.

Michał


On 13/05/17 08:41, Santanu77 wrote:

Hi Michal

I mean eventual consistency only.

Another use case for such data consistency is for Microservices.

While each microservice will have its own data - certain entities are 
required to be in synch across services.


Can consistency (eventual, of course) can be maintained by having 
akka? If yes, what is the reference architecture for such 
implementations?


Thanks
Santanu

On Monday, 8 May 2017 17:15:26 UTC+8, Michal Borowiecki wrote:

Hi Santanu,

If data consistency is key, please start by thinking carefully
about what you mean by consistency. How strong your consistency
guarantees actually need to be?

I see no reason not to build your system using akka, but be aware
that message-driven distributed systems will generally offer at
most eventual consistency and only provided they're implemented
thoughtfully.

Cheers,

Michal


On 08/05/17 03:37, Santanu Dey wrote:

*Please suggest if Akka can be used for the following use case:*


I have to run an application for two different user groups one
from the Intranet and another from the Internet.

The company policy requires me to run this applications from two
different hosting sites

Each site would contain its own DB, App and Web server resources.

However the application copy on either side should be consistent
with respect to data.

Only communication between these two layers are allowed via a
message queue.

*Questions*

 1. Can Akka be used on both sides application layer to solve the
data consistency problem on either copies of the application?
 2. Can Akka make use of the message queue for communicating
between the hosting site A to hosting site B?

Thanks

Santanu Dey
-- 
>> Read the docs: http://akka.io/docs/

>> Check the FAQ:
http://doc.akka.io/docs/akka/current/additional/faq.html

>> Search the archives:
https://groups.google.com/group/akka-user

---
You received this message because you are subscribed to the
Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it,
send an email to akka-user+...@googlegroups.com .
To post to this group, send email to akka...@googlegroups.com
.
Visit this group at https://groups.google.com/group/akka-user
.
For more options, visit https://groups.google.com/d/optout
.


-- 
 	Michal Borowiecki

Senior Software Engineer L4
T:  +44 208 742 1600


+44 203 249 8448



E:  michal.b...@openbet.com 
W:  www.openbet.com 


OpenBet Ltd

Chiswick Park Building 9

566 Chiswick High Rd

London

W4 5XT

UK




This message is confidential and intended only for the addressee.
If you have received this message in error, please immediately
notify the ...@openbet.com  and delete it from your
system as well as any copies. The content of e-mails as well as
traffic data may be monitored by OpenBet for employment and
security purposes. To protect the environment please do not print
this e-mail unless necessary. OpenBet Ltd. Registered Office:
Chiswick Park Building 9, 566 Chiswick High Road, London, W4 5XT,
United Kingdom. A company registered in England and Wales.
Registered no. 3134634. VAT no. GB927523612

--
>> Read the docs: http://akka.io/docs/
>> Check the FAQ: 
http://doc.akka.io/docs/akka/current/additional/faq.html

>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the 

[akka-user] How to map unstructured Json to a case class in Akka-Http

2017-05-13 Thread vishal . verma
   
I am trying to create the REST service using akka Http and slick . I am 
trying to persist the Raw json in the MySql table in string format or BLOB 
format whichever can solve my problem.
The point where I am facing issues is Every time I try to store the Json 
via akka http routes , It throws an error about json being malformed.

object Models {
  case class Customer(name: String,jsonData:String)
  object ServiceJsonProtoocol extends DefaultJsonProtocol {
implicit val customerProtocol = jsonFormat2(Customer)
  }
}

object AkkaJsonParsing {



  def main(args: Array[String]) {

implicit val actorSystem = ActorSystem("rest-api")

implicit val actorMaterializer = ActorMaterializer()

val list = new ConcurrentLinkedDeque[Customer]()

import ServiceJsonProtoocol.customerProtocol
val route =
  path("customer") {
post {
  entity(as[Customer]) {
customer => complete {
  list.add(customer)
  s"got customer json ${customer.jsonData}"
}
  }
}





Json 
{
"name":"test",
   "json":[{"type":"alpha","gross":"alpha"}]

}



Error :Request was rejected with rejection 
MalformedRequestContentRejection(Expected String as JsString, but got 
[{"type":"alpha","gross":"alpha"}],None)


I tried changing case class jsonData datatype to Byte,Array[Byte] but 
nothing helps. 
what is the right way to persist whole json?

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.


Re: [akka-user] Re: Akka-http: how to deal with incorrect http headers

2017-05-13 Thread Florian Rosenberg
I'm seeing a similar problem, but not wit the URI but with the 
Strict-Transport-Header, it seems to be invalid, changing the conf to 
ignore it has no effect. I'm using a websocket though.

After debugging around for a while, I instrumented some code and see this:

Illegal 'strict-transport-security' header: Invalid input 'EOI', expected 
OWS, 'i' or token0 (line 1, column 18): max-age=31536000;

It may well be that the endpoint I'm sending it to does not treat this 
correctly and returns a 400 (Bad request), but I need to be able to ignore 
this somehow. 


On Tuesday, June 30, 2015 at 12:59:48 PM UTC+2, driak wrote:
>
> Hello,
>
> I'm running into the same problem, did you ever find out how to resolve 
> this issue?
>
>
>
>
> On Sunday, February 1, 2015 at 12:01:13 AM UTC+1, rklaehn wrote:
>>
>> I have looked at the reference.conf of akka-http-core-experimental 
>> (1.0-M2) and found the following settings that should solve some of 
>> these problems. But adding the configuration below as an 
>> application.conf does not seem to make a difference WRT. parsing of 
>> Uris. I still get a "400 Bad Request" for queries containing ";". 
>>
>> Any ideas? 
>>
>> application.conf: 
>>
>> akka.http { 
>>
>>   parsing { 
>>
>> # Sets the strictness mode for parsing request target URIs. 
>> # The following values are defined: 
>> # 
>> # `strict`: RFC3986-compliant URIs are required, 
>> # a 400 response is triggered on violations 
>> # 
>> # `relaxed`: all visible 7-Bit ASCII chars are allowed 
>> # 
>> # `relaxed-with-raw-query`: like `relaxed` but additionally 
>> # the URI query is not parsed, but delivered as one raw string 
>> # as the `key` value of a single Query structure element. 
>> # 
>> uri-parsing-mode = relaxed-with-raw-query 
>>
>> # Enables/disables the logging of warning messages in case an 
>> incoming 
>> # message (request or response) contains an HTTP header which cannot 
>> be 
>> # parsed into its high-level model class due to incompatible syntax. 
>> # Note that, independently of this settings, akka-http will accept 
>> messages 
>> # with such headers as long as the message as a whole would still be 
>> legal 
>> # under the HTTP specification even without this header. 
>> # If a header cannot be parsed into a high-level model instance it 
>> will be 
>> # provided as a `RawHeader`. 
>> illegal-header-warnings = off 
>>   } 
>> } 
>>
>> On Sat, Jan 31, 2015 at 6:27 PM, rklaehn  wrote: 
>> > Here is an example of an URL that works fine without the proxy, but 
>> causes a 
>> > parse error when going via the proxy: 
>> > 
>> > 
>> http://forum.nasaspaceflight.com/index.php?action=dlattach;topic=34835.0;attach=633689
>>  
>> > 
>> > curl 
>> > "
>> http://forum.nasaspaceflight.com/index.php?action=dlattach;topic=34835.0;attach=633689;
>>  
>>
>> > 
>> > => lots of binary data 
>> > 
>> > 
>> > curl --proxy 127.0.0.1 
>> > "
>> http://forum.nasaspaceflight.com/index.php?action=dlattach;topic=34835.0;attach=633689;
>>  
>>
>> > 
>> > => Illegal request-target: Invalid input ';', expected '+', query-char, 
>> '%', 
>> > '&' or 'EOI' (line 1, column 59) 
>> > 
>> > 
>> > log: 
>> > [WARN] [01/31/2015 18:25:05.165] 
>> [Proxy-akka.actor.default-dispatcher-23] 
>> > [ActorSystem(Proxy)] Illegal request, responding with status '400 Bad 
>> > Request': Illegal request-target: Invalid input ';', expected '+', 
>> > query-char, '%', '&' or 'EOI' (line 1, column 59): 
>> > 
>> http://forum.nasaspaceflight.com/index.php?action=dlattach;topic=34835.0;attach=633689
>>  
>> > 
>> > 
>> > Am Samstag, 31. Januar 2015 17:46:19 UTC+1 schrieb rklaehn: 
>> >> 
>> >> Hi all, 
>> >> 
>> >> While playing around with akka-http, I wrote a minimal http proxy 
>> server: 
>> >> https://gist.github.com/rklaehn/3aa3215046df2c0a7795 
>> >> 
>> >> To test it, I configured a browser with this as proxy and browsed some 
>> >> popular news web pages that load a zillion things from ad servers, 
>> >> trackers and the like. 
>> >> 
>> >> It works just fine, but I get a large number of warnings and the 
>> >> occasional error in the log because apparently a lot of the 
>> >> "secondary" traffic going over the proxy is not 100% correct according 
>> >> to the HTTP spec. See some examples below. 
>> >> 
>> >> Is it possible to tell akka-http to ignore errors such as 
>> >> IllegalResponseException and just pass through everything? I don't see 
>> >> a single line of my own code in the stack traces, so I am a bit at a 
>> >> loss how to approach this. 
>> >> 
>> >> Cheers, 
>> >> 
>> >> Rüdiger 
>> >> 
>> >> --- 
>> >> Opening connection to weltonline01.webtrekk.net 
>> >> [WARN] [01/31/2015 17:33:42.631] 
>> >> [MinimalProxy-akka.actor.default-dispatcher-70] 
>> >> [ActorSystem(MinimalProxy)] Illegal request header: Illegal 'cookie' 
>> >> header: Invalid input ',', expected tchar, '\r', WSP or '=' (line 1, 
>> >> 

Re: [akka-user] Using Akka for Data Synchronization Use Case

2017-05-13 Thread Santanu77
Hi Michal

I mean eventual consistency only.  

Another use case for such data consistency is for Microservices.

While each microservice will have its own data - certain entities are 
required to be in synch across services. 

Can consistency (eventual, of course) can be maintained by having akka? If 
yes, what is the reference architecture for such implementations? 

Thanks
Santanu

On Monday, 8 May 2017 17:15:26 UTC+8, Michal Borowiecki wrote:
>
> Hi Santanu,
>
> If data consistency is key, please start by thinking carefully about what 
> you mean by consistency. How strong your consistency guarantees actually 
> need to be? 
>
> I see no reason not to build your system using akka, but be aware that 
> message-driven distributed systems will generally offer at most eventual 
> consistency and only provided they're implemented thoughtfully.
>
> Cheers,
>
> Michal
>
> On 08/05/17 03:37, Santanu Dey wrote:
>
> *Please suggest if Akka can be used for the following use case:*
>
>
> I have to run an application for two different user groups one from the 
> Intranet and another from the Internet.  
>
> The company policy requires me to run this applications from two different 
> hosting sites 
>
> Each site would contain its own DB, App and Web server resources. 
>
> However the application copy on either side should be consistent with 
> respect to data. 
>
> Only communication between these two layers are allowed via a message 
> queue. 
>
> *Questions*
>
>1. Can Akka be used on both sides application layer to solve the data 
>consistency problem on either copies of the application? 
>2. Can Akka make use of the message queue for communicating between 
>the hosting site A to hosting site B? 
>
> Thanks 
>
> Santanu Dey
> -- 
> >> Read the docs: http://akka.io/docs/
> >> Check the FAQ: 
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >> Search the archives: https://groups.google.com/group/akka-user
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to akka-user+...@googlegroups.com .
> To post to this group, send email to akka...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
> -- 
>  Michal Borowiecki 
> Senior Software Engineer L4 
> T: +44 208 742 1600 
>
>
> +44 203 249 8448 
>
>
>   
> E: michal.b...@openbet.com  
> W: www.openbet.com 
> OpenBet Ltd 
>
> Chiswick Park Building 9 
>
> 566 Chiswick High Rd 
>
> London 
>
> W4 5XT 
>
> UK 
>  
> This message is confidential and intended only for the addressee. If you 
> have received this message in error, please immediately notify the 
> ...@openbet.com  and delete it from your system as well as 
> any copies. The content of e-mails as well as traffic data may be monitored 
> by OpenBet for employment and security purposes. To protect the environment 
> please do not print this e-mail unless necessary. OpenBet Ltd. Registered 
> Office: Chiswick Park Building 9, 566 Chiswick High Road, London, W4 5XT, 
> United Kingdom. A company registered in England and Wales. Registered no. 
> 3134634. VAT no. GB927523612 
>

-- 
>>  Read the docs: http://akka.io/docs/
>>  Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>  Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.