Friday, April 25, 2014

How To: Test Activemq 5.9.1 Master/Slave by replicatedLevelDB/Zookeeper

Start from 5.9, Activemq comes with another HA option called ReplicatedLevelDB. I would recommend start from 5.9.1 at least, and I found a lot bugs in the 5.9.
  basic idea, Zookeeper as the central coordination point, every broker talked to the Zk , ZK wills tell the member information like who is the master. slave talks to master node to fetch the incremental change when it come online.
 
for the configuration, each member in a cluster share the same broker name, zookeepeer address, and zkPass.

image

and transportconnector is transparent to the underlining persistence layer.

image

when you startup the broker, for the 1st one, since we setup the replica to 2,that means we have to start at least 2 brokers to meet the quota requirement.
 image

after 2 broker ready, you can see it’s a slave node,
image

for the 1st ndoe, which is the master node, will turn on the transportconnector that is openwire here,
image

3rd one will be a slave node too.
image

Thursday, April 24, 2014

How To: test Activemq using Maven plugins

ActiveMQ has two useful Maven plugins which enable you to test different Activemq deployment layout and Performace (Producer/Consumer) quickly. the plugins have been renamed since 5.7, and this demo is based on latest version 5.9.

Demo: Setup one standard broker quickly.

Create one maven eclipse project, and add the plugin dependency called activemq-maven-plugin to the POM file.
image

Now the pom.xml looks like this

image

for this plugin , we will add configuration later on this plugin, like the Activem.xml config, etc.
now by default, we can run the plugin on the command

image

then A simple queue broker is there, and by default using the openwire transport and memoryPersistenceAdapter.

image

TO Change the configuration, we can customize the plugin.
we setup the persistent=true and use 8888 as the openwire port.
image

Run Again,
image

if we want to change it to levelDB or more customized setting,
image

 

For the producer, you can setup another plugin, here I setup two profile, one for producer and another one is for consumer

image

the for producer, you can add different settings by passed –D to the command,
image

and consumer,
image

to start another consumer , change the prefix , otherwise, they want get any message, since they use the same consumerid

image

after done, you should see some test results, like

image

Tuesday, March 25, 2014

SoapUI, Groovy Script tutorial

Groovy is built on JVM, so does the SoapUI, it’s no surprise that SoapUI offers the Groovy script support by default. Let’s do a simple test, basically send out a Http request with dynamic parameters, and parse the result using the regular expression capability of Groovy and IO capablity to save the result back to a file. for the parameter we can use the groorvy to poll a file and return some randomized keywords.

so the keywords file looks like
image

we create one project with one test suite, then under the suite, we can add test case, and for the test step, let’s add first step called GetKeyword as a groovy script.


image

then we put some script here, which will assign a keyword property to the context randomly.
image

then we can access this keyword using context.keyword in next step, now, let’s create a http request to bing.com

image

Click extract params,now if we run this test

image

the query keyword is hardcoded, we can replace it with a groovy expression

image

then add the 3rd step, that we read the response in step 2 and save it to a file

image

if we run the test case, you will see file named keyword.txt with the http response from bing.com search

also you can just copy and save the following xml as a project file, you open in in SoapUI

<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project activeEnvironment="Default" name="tst" soapui-version="4.6.4" xmlns:con="http://eviware.com/soapui/config"><con:settings/><con:testSuite name="testgroovy"><con:settings/><con:runType>SEQUENTIAL</con:runType><con:testCase failOnError="true" failTestCaseOnErrors="true" keepSession="false" maxResults="0" name="TestCase 1" searchProperties="true" id="cdd185b8-b6ae-4455-9713-ec70b5404569"><con:settings/><con:testStep type="groovy" name="GetKeyword"><con:settings/><con:config><script>def file=new File("c:\\a.txt")
def lines=file.readLines();
def randomindex=new Random()
def keyword=lines[randomindex.nextInt(lines.size())];
context.keyword=keyword
log.info(keyword)</script></con:config></con:testStep><con:testStep type="httprequest" name="Req2Bing"><con:settings/><con:config method="GET" xsi:type="con:HttpRequest" name="Req2Bing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><con:settings><con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers">&lt;xml-fragment/></con:setting></con:settings><con:endpoint>http://www.bing.com/search</con:endpoint><con:request/><con:credentials><con:authType>Global HTTP Settings</con:authType></con:credentials><con:jmsConfig JMSDeliveryMode="PERSISTENT"/><con:jmsPropertyConfig/><con:parameters><con:parameter><con:name>q</con:name><con:value>${=context.keyword}</con:value><con:style>QUERY</con:style><con:default>androidyou</con:default><con:path xsi:nil="true"/><con:description xsi:nil="true"/></con:parameter></con:parameters></con:config></con:testStep><con:testStep type="groovy" name="SaveitToFile"><con:settings/><con:config><script>def resp=testRunner.getTestCase().getTestStepByName("Req2Bing").httpRequest.response
def raw=resp.getContentAsString()
//save it fo file
def resultFile=new File("c:\\" + context.keyword + "t.txt")
resultFile.write(raw);</script></con:config></con:testStep><con:properties/></con:testCase><con:properties/></con:testSuite><con:properties/><con:wssContainer/></con:soapui-project>

Monday, March 24, 2014

WMIC Tips, Export format and get hint about callable Actions

On windows , you can use wmic to list all process running by type process in the wmic console.
image

Also you can run some filter, like listing all  notepad.exe
procecss where name=”notepad.exe” list brief

image

if we don’t know which field are available to get for this Process object, try get /?

image

so we can call process where name=”notepad.exe” get commandline, name, processid

image

if we want to kill those processes, we can call call /? to see available actions

image

So we can call terninate method to kill all notepad.exe

image

then all process are gone,

we can do this same thing on service,

image

to export all the service you can run wmic /output:file  service where state=”running” /format:htable

image

image

Thursday, March 13, 2014

Apache Archiva, yet another simple Maven repository in your enterprise

Before I got a chance to play Archiva, I’ve always used the Nexus as the my maven repository across different machines. Now it turns out the Archiva is very easy to use and pretty powerful for most features I used in Nexus.
  Apache archiva is s standard jsp application, we can hosted in any container or just run as standalone,
image

the major usage of Archiva for me is to use it as a central repository to store all my artifacts. Basically when you are done with your project, run a “maven deploy” it will deploy it to your central repository, then across the computers you work, you can find those jars both on runtime or compile time. 

To do that, we need config a setting on the ~/.m2/settings.xml, put the server credentials there , and one your project pom file, put the repository as one of the distributionManagement subnode.

on the settings.xml,
add my own repositories that are proxyed and cached to remote,
image

then on the client pom.xml. just add the repository to the distributionmgmt

image

then once we run the mvn deploy, it will be deployed to the centorl internal repo.

Monday, March 10, 2014

Apache Camel tutorial : Quick start from scratch (Console App using Xml as the routes definition , without Spring)

Following the last post Apache Camel tutorial : Quick start from scratch (Console App , without Spring), if you don’t want to hard code the routes, we can simply use xml as keep the routes definition.

to do that , let’s change the code a little bit.

image

then in the route.xml, add the route definition there,
image

when run, you see the similar results,

image

for this code, check the branch demoxml

https://github.com/ryandh/apacheCamelTutorial/tree/demoxml

Apache Camel tutorial : Quick start from scratch (Console App , without Spring)

Apache Camel is one great implementation of the EIP pattern, If you are not a seasoned Spring/Java developer , you might found it’s hard to get started, the goal of this post is simplify that process and show you how easy to get started without remember any code snippet. we will use plain console app to host and start one camel route.

to get started, simply open eclipse and create one maven project (the purpose of maven here is to add those dependency automatically), if you don’t have any maven experience, you can simply download the required jar and add to you build path.

Create one Maven project , using the simple project type, we get one project with maven ready,
image

Create one simple class with main method,
image

Now , right click pom.xml, click maven menu,  add a dependency to camel-core, you can simply search camel-core

image

Now, we can start coding,
image

we’ve initialized the camelcontext, next step is adding our routes by xml or java code.

let’s start from java code first, since it has intelligence and life is little bit easier,

image

it looks like we can just add one RoutesBuilder to the context, is there any existing one, or we have to build our own.
ask the eclipse create a local variable for the routesbuilder, let’s see whether there is any existing one,

image

it turns out Routesbuilder is a interface, and have RoutesBuilder as an implementation, so let’s extends that one,
image

then the code looks like this,

image

in the configure , we just inject the code snippets listed on the camel component page, here is one demo, that dump out some message every 2 seconds,

image

if we run this, we can see the message get shown in the console every 2 seconds.

for the log component, we can’t see the message because it is NOP for slf4j by default, so lets add a slf4j-simple to the pom.xml

image

run again, you can see the message is listed in the console window.
image

if we want to export this as a executable jar, go to the pom.xml ,right click maven menu to add a mvn-assemly-plugin
image

Change the pom.xml a little big , pint to the mainclass , you can copy the xml here
image

then go to the project folder, run mvn compile assemlby : Single

image

you will see a jar in the target folder,
image

Now, we can run the jar directly, by typing java –jar pathtothejar

image

image

for the source code, check it out here, https://github.com/ryandh/apacheCamelTutorial/tree/DemoConsole

 
Locations of visitors to this page