Return-Path: X-Original-To: apmail-activemq-dev-archive@www.apache.org Delivered-To: apmail-activemq-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C266D17225 for ; Fri, 13 Mar 2015 16:13:48 +0000 (UTC) Received: (qmail 36050 invoked by uid 500); 13 Mar 2015 16:13:48 -0000 Delivered-To: apmail-activemq-dev-archive@activemq.apache.org Received: (qmail 35990 invoked by uid 500); 13 Mar 2015 16:13:48 -0000 Mailing-List: contact dev-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list dev@activemq.apache.org Received: (qmail 35978 invoked by uid 99); 13 Mar 2015 16:13:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2015 16:13:48 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jakub.korab.lists@gmail.com designates 209.85.212.182 as permitted sender) Received: from [209.85.212.182] (HELO mail-wi0-f182.google.com) (209.85.212.182) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Mar 2015 16:13:43 +0000 Received: by widfb4 with SMTP id fb4so13360240wid.0 for ; Fri, 13 Mar 2015 09:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=EthKYwpZKI6EXvEziKX3McvMF5PCWnC5E37T1CfM+N4=; b=omyvFJu1duKh5jdTyU6OLNAr6NcgJOggsRv4vWnuPjIVg5nA43ecVigAHQJg9BRmuB rS9MAUF071S/X2rJO2KUpdoiJsgzYVZnHZ3ViCKmi9tV5emZWaMR1dOmcVKsO/w2a6Qr WiK1bDA6siJOKl9+DMqVCahQP5R29pPRS4SQ5gOd/P1D4fxOTDtMNIHC7KLgajYq2LpP jiJYLQAwemas8td4rM2vYVQV/8vVcFkUCfT3j1nD7+PUtS3rmhWTJJWosIZD6UVfV7lb ydEihGiVdtsZ70e26IfQ+f4dQ1g3KmyvlX+G5app/M2zJ0/pQdq4Cn48YC11Xvt3fnDP g82w== X-Received: by 10.180.35.97 with SMTP id g1mr22906501wij.17.1426263202374; Fri, 13 Mar 2015 09:13:22 -0700 (PDT) Received: from [192.168.0.3] ([176.253.20.5]) by mx.google.com with ESMTPSA id vv9sm3420326wjc.35.2015.03.13.09.13.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 09:13:21 -0700 (PDT) Message-ID: <55030CA0.5000408@gmail.com> Date: Fri, 13 Mar 2015 16:13:20 +0000 From: Jakub Korab User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: dev@activemq.apache.org Subject: ActiveMQ DSLs Content-Type: multipart/alternative; boundary="------------020106060603000209020501" X-Virus-Checked: Checked by ClamAV on apache.org --------------020106060603000209020501 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi All, In working on a separate project, I found the need to instantiate multiple different ActiveMQ configurations. Rather than writing up a lot of different XML configs or messing around with assembling BrokerService instances, I wrote a DSL that mimics the ActiveMQ config schema via a directed builder pattern, much like Camel. Here's an example: BrokerContext context = new BrokerContext(ActiveMQBrokers.broker("embeddedBroker").useJmx(false).persistent(false) .transportConnectors() .transportConnector("openwire", "tcp://0.0.0.0:61616").end() .end() .plugins() .simpleAuthenticationPlugin() .users() .authenticationUser("user").password("pass").groups("guests").end() .end() .end() .end())); context.start(); ... context.end(); Unlike Camel, the DSL itself defines a model that is used to instantiate a BrokerService. Camel has an intermediate set of VOs (org.apache.camel.model) between the Java DSL and the implementation. I had a go at generating a similar model via JAXB from the ActiveMQ schema, to abstract away the DSL/XBean config, but the generated classes were hideous and I abandoned the approach. I also developed a testing DSL for JUnit that allows you to spin up these configurations, and rely on the JUnit runner to start up and shut down the broker. The test DSL also allows for the definition of proxies (using the ActiveMQ SocketProxy class) to easily simulate network outages. A full writeup and source code are available at https://github.com/jkorab/activemq-dsls As it stands, the DSL is a work in progress that supports my own code, but I think it would be useful as something provided by ActiveMQ itself. I would like to contribute what I have written so far, and develop it further (perhaps cleaning up a bunch of ActiveMQ tests to use it in an "eating your own dogfood" way). I was initially thinking that it could be part of activemq-broker in the src/test tree, and once it gets fleshed out, moved to src/main. The set of config options in ActiveMQ is huge, and retrofitting tests would be an ideal way of evolving it and validating that everything works before making it public. I think that this is something that would be useful, as I have seen ActiveMQ deployments where the broker was defined in Java. This is particularly useful where there are is a broker network with a bunch of network connectors from a broker, each with dynamically or statically included or excluded destinations, used in conjuction with composite destinations to route messages in "just the right way". That sort of thing is much better expressed in code rather than huge slabs of XML. What do you think? Is this something that would be worthwhile to have in ActiveMQ? Jakub --------------020106060603000209020501--