These classes are an alternative to using the official Microsoft Azure ServiceBus library (Java) Databinder.dispatch used to implement asynchronous REST calls against the ServiceBus API. Generates a SAS key from configured credentials.
The target language is Scala version 2.12, and uses the build tool sbt 1.2.1. Clone this repository in a fresh directory:
% git clone git@bitbucket.org:royp/bluebus.git
Compile the example with the following command:
% sbt clean compile
[info] Done compiling.
[success] Total time: 6 s, completed 12-Aug-2018 11:38:12
The only explicit library dependency outside of the Scala language environment is Databinder dispatch version 0.13.4
Azure ServiceBus provides a REST API to reqad and to enqueue messages
Requests to the API are authorized by the provision of a Shared Access Signature (SAS) token in the request head. This is generated by the library based on configuration parameters (see below)
The client can either be configured directly with the SBusCOnfig
class constructor, or by passing a Map[String,String]
containing the following key/values:
key | purpose | example | default |
---|---|---|---|
root-uri |
base | 127.0.0.1 |
-- |
queue-name |
name of queue | test |
-- |
sas-key-name |
SAS key name | sbuser |
-- |
sas-key |
SAS key | 12345 |
-- |
token.ttl |
Auth token time-to-live | PT5M |
1 min |
read.timeout |
Read timeout | PT30S |
30 secs |
The app below will read message from the specified queue, printing the message body. until no more are available.
import java.net.URI
import java.util.concurrent.Executors
import bluebus.client.ServiceBusClient
import bluebus.configuration.SBusConfig
import scala.concurrent.duration._
import scala.concurrent._
object SampleReceiver extends App {
implicit val ec = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(10))
val busConfig = SBusConfig(
rootUri=URI.create("http://samplens.servicebus.windows.net"),
queueName="queueName",
sasKeyName="RootManageSharedAccessKey",
sasKey="yourKey")
val incomingService = new ServiceBusClient(busConfig)
/** continually receive & handle messages from endpoint, until no more available */
def receiveMessages(f: String => Unit): Future[String] =
incomingService.receive flatMap { message =>
f(message)
receiveMessages(f)
}
val reader = receiveMessages((p: String) => println(p))
Await.ready(reader, 2 seconds)
}
Run the test suite to verify correct behaviour.
From the command line:
% sbt test
To measure test coverage, this app uses the 'scoverage' SBT plugin. To create the report, rom the command line:
% sbt coverage test coverageReport
(c) 2018 This project is licensed under Creative Commons License
Attribution 4.0 International (CC BY 4.0)