theiterators / akka-http-microservice Goto Github PK
View Code? Open in Web Editor NEWExample of http (micro)service in Scala & akka-http
License: MIT License
Example of http (micro)service in Scala & akka-http
License: MIT License
Please update to Akka Streams 1.0.
This template is rather high up in google search results, it would be awesome if it would be up to date. π
Thanks!
From http://www.telize.com:
The public API will permanently shut down on November 15th, 2015. More information can be found here [http://www.cambus.net/adventures-in-running-a-free-public-api/].
To continue using Telize after this date, please spin up your own instance or subscribe to a paid plan.
HI there,
as soon as I try to build the project I'm getting this:
stondo@H97-D3H:~/dev/scala/akka-http-microservice-quickstart$ sbt
[info] Loading project definition from /home/stondo/dev/scala/akka-http-microservice-quickstart/project
[error] [/home/stondo/dev/scala/akka-http-microservice-quickstart/build.sbt]:64: ';' expected but 'true' found.
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
Anyone know what might be wrong? Installed Scala 2.11.7 with sdkman.io and using Ubuntun 14.04. Sbt version is 0.13.9
Thanks in advance for your help
Please, explain current status of dependencies that ends in -experimental
. Are they production-ready?
I have used this template to create a search rest API for my project. I have deployed my micro service in AWS EBS with Docker setup. I have allocate 512 MB Memory for docker. When I request my rest API from some tool(post man/j meter) the heap memory and CPU utilization was increased, after the stop the request CPU utilization decreased but heap memory not decreased instead when the next set ot request comes heap memory increased again.
There is any was to fix this issue by clearing the unused objects from the Scala code. I need to close(shutdown) the actor object manually or it will be deleted by the JVM's GC.
Error running akka-http-microservice Activator template
Unable to run example template: akka-http-microservice from the Activator
Project builds, but on running, unable to access URL, http://localhost:9000/ip/8.8.8.8 getting 'Internal Server Error'
Error on running service: [ERROR] [04/21/2016 12:06:35.506] [default-akka.actor.default-dispatcher-10] [akka://default/user/StreamSupervisor-0/flow-2-0-unknown-operation] Error in stage [One2OneBidi]: Inner stream finished before inputs completed. Outputs might have been truncated. (akka.http.impl.util.One2OneBidiFlow$OutputTruncationException$)
This is just with code taken directly from downloaded template *.zip file.
Running on Mac OSx, El Capitan. Running Scala v2.10.3. Activator v1.3.9
Would you be able to shed light on this problem? https://stackoverflow.com/q/47636871/839733
My current REST APIs have something like [api-url]?start=[parameter]&end=[parameter].
How do I handle this with the template. Relatively new to Akka
Thanks
Errors should really be JSON responses with appropriate Content-Types
headers.
The following sends a JSON request using Accept
and Content-Types
set to application/json
:
β ~ http -j http://localhost:9000/ip/8.8
HTTP/1.1 406 Not Acceptable
Content-Length: 78
Content-Type: text/plain; charset=UTF-8
Date: Sun, 01 Feb 2015 10:43:21 GMT
Server: akka-http/2.3.9
Resource representation is only available with these Content-Types:
text/plain
When I explicitly say I'm accepting test/plain
it's fine:
β ~ http -j http://localhost:9000/ip/8.8 Accept:text/plain,application/json
HTTP/1.1 400 Bad Request
Content-Length: 24
Content-Type: text/plain; charset=UTF-8
Date: Sun, 01 Feb 2015 10:44:13 GMT
Server: akka-http/2.3.9
8.8: incorrect IP format
The same happens with the following when it's implicitly assumed POST in JSON Accept
and Content-Types
headers:
β ~ http http://localhost:9000/ip/8.8.8.8 ip1=8.8.8.8 ip2=8.8
HTTP/1.1 406 Not Acceptable
Content-Length: 78
Content-Type: text/plain; charset=UTF-8
Date: Sun, 01 Feb 2015 10:46:06 GMT
Server: akka-http/2.3.9
Resource representation is only available with these Content-Types:
text/plain
With explicitly accepting non-JSON responses using Accept:text/plain
it works:
β ~ http http://localhost:9000/ip/8.8.8.8 Accept:text/plain,application/json ip1=8.8.8.8 ip2=8.8
HTTP/1.1 400 Bad Request
Content-Length: 24
Content-Type: text/plain; charset=UTF-8
Date: Sun, 01 Feb 2015 10:45:07 GMT
Server: akka-http/2.3.9
8.8: incorrect IP format
Please upgrade the sample so it uses a stable version instead of the RC :)
As an example:
<li>learn <a href="#tutorial/1" class="shortcut">what a microservice is</a>,</li>
but there's no anchor defined
<div> <h2>What is a microservice?</h2> <p>
An id
attribute or an <a name>...</a>
element needs to be defined for these to work.
Hi, how to manage a akka-http-microservice?
For example, configuration, service registry & discovery, log, metrics, tracing, load balancing, rate limit...
Well..
Not a big deal but confused me until I looked at the commit log.
I have added validation to the case class and changed the tests to use Route.seal or inside(rejection). But the test fails with error
- should respond with bad request on incorrect IP format *** FAILED ***
[info] java.lang.IllegalArgumentException: requirement failed: wrong IP address
It's similar to this question but I Post doesn't accept JsObject
case class IpPairSummaryRequest(ip1: String, ip2: String) { require(ip2.split('.').map(oktet => Try(oktet.toInt)).map(x => x.getOrElse(-1)).map({s => s >= 0 && s <= 255}).forall(x => x), "wrong IP address") }
tests
it should "respond with bad request on incorrect IP format" in {
Post(s"/ip", IpPairSummaryRequest(ip1Info.query, "asdfg")) ~> Route.seal(routes) ~> check {
status shouldBe BadRequest
responseAs[String].length should be > 0
}
Post(s"/ip", IpPairSummaryRequest(ip1Info.query, "asdfg")) ~> routes ~> check {
inside(rejection) {
case ValidationRejection("requirement failed: wrong IP address", _) =>
}
}
}
Please note there's a couple great discussions discouraging the use of Source.single
when sending a request list is done in the AkkaHttpMicroservice:
https://doc.akka.io/docs/akka-http/current/client-side/host-level.html?language=scala#examples
At this place we previously showed an example that used the Source.single(request).via(pool).runWith(Sink.head). In fact, this is an anti-pattern that doesnβt perform well. Please either supply requests using a queue or in a streamed fashion as shown below.
You might want to consider just adding a comment in your code referencing this so as to not advertise this anti-pattern as the Akka docs describe it (if not refactor the code a bit to make use of host-level api)
Hi,
Any example incorporating the proxy settings such as this:
https://gist.github.com/rklaehn/3aa3215046df2c0a7795
Thanks,
Henry
Can I do this for a case object?
trait Protocols extends DefaultJsonProtocol {
Β implicit val ipInfoFormat = jsonFormat5(IpInfo.apply)
Β implicit val ipPairSummaryRequestFormat = jsonFormat2(IpPairSummaryRequest.apply)
Β implicit val ipPairSummaryFormat = jsonFormat3(IpPairSummary.apply)
}
It seems it's not up to date in the activator registry somehow?
Caused confusion for some users: akka/akka#17600 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.