Skip to content

sothach/bluebus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure ServiceBus Client

Status

Build Status Coverage Status Codacy Badge

Scala client for Azure ServiceBus

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.

Prerequisites

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

Library design

ServiceBus REST API

Azure ServiceBus provides a REST API to reqad and to enqueue messages

Shared Access Signature

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)

Configuration

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

Sample usage

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)
}

Testing

Running the tests

Run the test suite to verify correct behaviour.

From the command line:

% sbt test

Test Coverage Report

To measure test coverage, this app uses the 'scoverage' SBT plugin. To create the report, rom the command line:

% sbt coverage test coverageReport

Author

License

License

(c) 2018 This project is licensed under Creative Commons License

Attribution 4.0 International (CC BY 4.0)

Releases

No releases published

Packages

No packages published

Languages