Skip to content
This repository was archived by the owner on Nov 14, 2017. It is now read-only.

Commit f6d4d9e

Browse files
committed
Merge pull request #2 from juan62/add_readme
Add readme
2 parents 91723e7 + de0b6e4 commit f6d4d9e

File tree

5 files changed

+126
-5
lines changed

5 files changed

+126
-5
lines changed

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Yoshitaka Okuda
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# sqscala
2+
simple AWS SQS client for Scala.
3+
4+
This library, has been inspired by [com.kifi.franz](https://github.com/kifi/franz).
5+
I like franz, but there are only a few of the configurations in order to create the AWS client.
6+
I wanted a more customizable interfaces.
7+
8+
## Installation
9+
10+
```
11+
resolvers += "jitpack" at "https://jitpack.io"
12+
libraryDependencies += "com.github.juan62" % "sqscala" % "1.0.0"
13+
```
14+
15+
## How to use
16+
17+
### 1a. prepare by application.conf(easy way)
18+
19+
put application.conf in your classpath(resources).
20+
21+
```conf
22+
aws {
23+
sqs {
24+
# endpoint-url or region
25+
# If you want to connect to localhost, example 'endpoint-url="http://localhost:9324"'
26+
# endpoint-url = null
27+
region = "us-west-2"
28+
29+
# max-retry = 3
30+
# max-connections = 50
31+
# connection-timeout-ms = 50000 # millis
32+
# socket-timeout-ms = 50000 # millis
33+
}
34+
}
35+
```
36+
37+
then your code, like
38+
39+
```scala
40+
import com.github.juan62.sqscala._
41+
42+
val client = ConfiguredSqsClient()
43+
```
44+
45+
### 1b. prepare by code
46+
47+
You can use SqsClient with credential provider and regions.
48+
In many cases, it is easy that you should use regions pattern.
49+
Of course, you can instantiate AWS client directly, and set SqsClient object to first argument.
50+
51+
```scala
52+
import com.amazonaws.regions.Regions
53+
import com.github.juan62.sqscala._
54+
55+
val client = SqsClient()
56+
// or
57+
val client = SqsClient(regions = Regions.US_WEST_2)
58+
// or
59+
val client = SqsClient(credentialProvider = new YourCustomCredentialProvider())
60+
```
61+
62+
### 2. connect the SQS via queue
63+
64+
Get a queue object from SqsClient.
65+
66+
```scala
67+
val queue = client.queue(QueueName("foo"))
68+
// or
69+
val queue = client.queue(QueueName("foo"), createIfNotExists = true)
70+
```
71+
72+
SqsQueue requires MessageSerializer used to serialize/deserialize the SQS message body.
73+
(Message Body <=> Any Type)
74+
By default, sqscala has only a StringSerializer(Message Body <=> String).
75+
You can switch it on implicit parameter.
76+
77+
```scala
78+
import com.github.juan62.sqscala.Implicits.stringSerializer
79+
// or
80+
implicit val serializer = YourOriginalSerializer
81+
```
82+
83+
then you can use queue, like
84+
85+
```scala
86+
// send message to SQS
87+
queue.send("hello, sqs.").onComplete {
88+
// ...
89+
}
90+
91+
// receive message from SQS
92+
queue.receive().onComplete {
93+
case Success(message) => // ...
94+
case Failure(exception) => // ...
95+
}
96+
97+
// delete message from SQS
98+
queue.receive().onSuccess {
99+
case Some(message) =>
100+
// ...
101+
queue.delete(message.receiptHandle).onComplete {
102+
// ...
103+
}
104+
}
105+
```
106+
107+
## Road map
108+
109+
1. support batch request.
110+
2. support queue attributes.
111+
3. support JSON serialization.

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ licenses +=("MIT", url("http://opensource.org/licenses/MIT"))
44

55
name := "sqscala"
66

7-
version := "1.0"
7+
version := "1.0.0"
88

99
scalaVersion := "2.11.7"
1010

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.github.juan62.sqscala.serializer
22

33
trait MessageSerializer[T] {
4+
type MessageBody = String
45

5-
def serialize(obj: T): String
6+
def serialize(obj: T): MessageBody
67

7-
def deserialize(messageBody: String): T
8+
def deserialize(messageBody: MessageBody): T
89
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.juan62.sqscala.serializer
22

33
object StringSerializer extends MessageSerializer[String] {
4-
override def serialize(obj: String): String = obj
4+
override def serialize(obj: String): MessageBody = obj
55

6-
override def deserialize(messageBody: String): String = messageBody
6+
override def deserialize(messageBody: MessageBody): String = messageBody
77
}

0 commit comments

Comments
 (0)