Friday, October 14, 2016

RabbitMQ SSL connection Using RabbitMQ Event Adpter in WSO2 CEP- Part 2

stHi all,


This is the continuous blog of this blog. In the previous blog we saw about rabbitMQ broker side configuration. Here we are going to see about specifying CEP side Configuration. RabbitMQ Receiver is an extension for the CEP. So we need to download it and put it into the CEP. Those are given below.

Steps 
  1.  Please visit this link to download RabbitMQ Receiver extension.
  2. Download rabbitmq client jar from this link. 
  3. Place the extension .jar file into the <CEP_HOME>/repository/components/dropins directory which you downloaded in step 1.
  4. Place the rabbitmq client .jar file into the <CEP_HOME>/repository/components/lib directory which you downloaded in step 2.
  5. Start the CEP Server by going to directory <CEP_HOME>/bin in terminal and giving command like sh ./wso2server.sh
  6. Create a Stream in CEP. Refer more here.
  7. Go to Main => Manage => Receiver to open the Available Receivers page and then click Add Event Receiver in the management console. You can get the management console by visiting the https://172.17.0.1:9443/carbon
  8. Select Input Event Adapter Type as rabbitmq.
  9. Then you will get a page like below.


   9. Then you need to specify values for the properties given above. Here I have mentioned important and  mandatory properties' values.

  • Host Name: localhost
  • Host Port: 5671
  • Username: guest
  • Password: guest
  • Queue Name: testsslqueue
  • Exchange Name: testsslexchange
  • SSL Enabled: True
  • SSL Keystore Location: ../client/keycert.p12
  • SSL Keystore Type: PKCS12
  • SSL Keystore Password: MySecretPassword
  • SSL Truststore Location: ../rabbitstore (These are the values we took from the part 1 blog step 5)
  • SSL Truststore Type: JKS
  • SSL Truststore Password: rabbitstore (The password is the one we used when we are key tool command in Step 5)
  • Connection SSL Version: SSL
After specifying above values, select the stream you had add in step 3 and save it. 

Then if there is a message in the queue you mentioned in RabbitMQ broker, you will get it into the CEP. The data from the queue can be used in further in Execution plan for processing and we can publish it.

Tuesday, September 6, 2016

Introduction to WSO2 BPS

We can use WSO2 BPS for efficient business Process Management by allowing easy deploy of business processes written using either WS-BPEL standard or BPMN 2.0 standard.

Business Process: Collection of related and structured activities or tasks, that meants a business use case and produces a specific service or output. A process may have zero or more well-defined inputs and an output.

Process Initiator: The person or Apps who initiates business process.

Human task: In here human interaction is involved in business process.

BPEL: It is an XML-based language used for the definition and execution of business. Composing of web services and orchestration.

BPMN: Graphical notation of business processes.

Simple BPEL Process Modeling
  • Download BPS product.
  • Go to <BPS_HOME> -> bin through terminal and execute sh ./wso2server.sh command.
  • Install the plug-in with pre-packaged Eclipse - This method uses a complete plug-in installation with pre-packaged Eclipse, so that you do not have to install Eclipse separately. On the WSO2 BPS product page, click Tooling and then download the distribution according to your operating system under the Eclipse JavaEE Mars + BPS Tooling 3.6.0 section.
  • Then we need to create carbon Composite Application Project. These steps clearly mentioned in https://docs.wso2.com/display/BPS360/BPEL+Guide
 

Friday, September 2, 2016

JAVA Flight Recorder with WSO2 Products

Brief JAVA Flight Recorder

A profiling and event collection framework built into the Oracle JDK. It gathers low level information about the JVM and application behavior without performance impact (less than 2%). With Java Flight Recorder system administrators and developers have a new way to diagnose production issues. JFR provides a way to collect events from a Java application from the OS layer, the JVM, and all the way up to the Java application. The collected events include thread latency events such as sleep, wait, lock contention, I/O, GC, and method profiling. JFR can be enabled by default and continuously collect low level data from Java applications in production environments. This will allow a much faster turnaround time for system administrators and developers when a production issue occurs. Rather than turning on data gathering after the fact, the continuously collected JFR data is simply written to disk and the analysis can be done on data collected from the application leading up to the issue, rather than data collected afterwards. We can use this JFR to do long run testing in effective way.


Here we will see using JFR to do long run testing to WSO2 products through JMC (JAVA Mission Control). Here I am taking WSO2 CEP as WSO2 Product.
  •  Go to <CEP_HOME>/bin and open wso2server.sh using gedit.
  • In that you can see $JAVACMD. Below that add these to enable JFR
    •  -XX:+UnlockCommercialFeatures \
    •   -XX:+FlightRecorder \
  • Start WSO2 CEP by using sh ./wso2server.sh in terminal.
  • Then start JMC by clicking on that. You can see this org.wso2.carbon.bootstrap.Bootstrap in that UI like below.

  • Right click on org.wso2.carbon.bootstrap.Bootstrap and click on start Flight Recording. Following window will be appear.


  • Then go to next steps and do your  relevant changes and click on Finish.
  • After specific time you mentioned you will get a .jfr file you can see the memory growth, cpu usage..... in that.
  • You can open this .jfr file anytime.

    Thanks all :)

Thursday, August 18, 2016

RabbitMQ SSL connection Using RabbitMQ Event Adpter in WSO2 CEP- Part 1

Hi all,

I am writing this blog by assuming you are familiar with RabbitMQ Broker. Here I mainly focus on Securing the connection between RabbirMQ Message Broker and WSO2 CEP. That means how to receive secure messages from RabbitMQ Broker from WSO2 CEP Receiver. The use case here going to explain is, CEP is going to act as a consumer and consumes messages from RabbitMQ server. So simply CEP will act as a Client and RabbitMQ Server Will act as the Server.

 Introduction to RabbitMQ SSL connection

In normal connection we send messages without secure. But some confidential information like credit card number, we can not send without secure. For that purpose, we use SSL. SSL stands for Secure Sockets Layer. SSL allows sensitive information to be transmitted securely. This layer ensures that all data passed between the server and client remain private and integral. SSL is an industry standard. SSL is a security protocol. Protocols describe how algorithms should be used. In this case, the SSL protocol determines variables of the encryption for both the link and the data being transmitted.

Steps 

  1.  As First Step we need to create own certificate Authority.
    • For that in terminal and go to specific folder (location) by using cd command.
    • Then use below commands.
      • $ mkdir testca
      • $ cd testca
      • $ mkdir certs private
      • $ chmod 700 private
      • $ echo 01 > serial
      • $ touch index.txt
    • Then create a new file using the following command, inside the tesca directory.  
      • $ gedit openssl.cnf

        When we using this commanda file will open in gedit. So copy and paste following thing and save it.

        [ ca ]
        default_ca = testca
        
        [ testca ]
        dir = .
        certificate = $dir/cacert.pem
        database = $dir/index.txt
        new_certs_dir = $dir/certs
        private_key = $dir/private/cakey.pem
        serial = $dir/serial
        
        default_crl_days = 7
        default_days = 365
        default_md = sha256
        
        policy = testca_policy
        x509_extensions = certificate_extensions
        
        [ testca_policy ]
        commonName = supplied
        stateOrProvinceName = optional
        countryName = optional
        emailAddress = optional
        organizationName = optional
        organizationalUnitName = optional
        
        [ certificate_extensions ]
        basicConstraints = CA:false
        
        [ req ]
        default_bits = 2048
        default_keyfile = ./private/cakey.pem
        default_md = sha256
        prompt = yes
        distinguished_name = root_ca_distinguished_name
        x509_extensions = root_ca_extensions
        
        [ root_ca_distinguished_name ]
        commonName = hostname
        
        [ root_ca_extensions ]
        basicConstraints = CA:true
        keyUsage = keyCertSign, cRLSign
        
        [ client_ca_extensions ]
        basicConstraints = CA:false
        keyUsage = digitalSignature
        extendedKeyUsage = 1.3.6.1.5.5.7.3.2
        
        [ server_ca_extensions ]
        basicConstraints = CA:false
        keyUsage = keyEncipherment
        extendedKeyUsage = 1.3.6.1.5.5.7.3.1
        
        • Now we can generate the key and certificates that our test Certificate Authority will use. Still within the testca directory:
          $ openssl req -x509 -config openssl.cnf -newkey rsa:2048 -days 365 -out cacert.pem -outform PEM -subj /CN=MyTestCA/ -nodes
          $ openssl x509 -in cacert.pem -out cacert.cer -outform DER

  2.  Generating certificate and key for the Server
    • Apply following commands. (Assuming you are still in testca folder)
      • $ cd ..
        $ ls
        testca
        $ mkdir server
        $ cd server
        $ openssl genrsa -out key.pem 2048
        $ openssl req -new -key key.pem -out req.pem -outform PEM -subj /CN=$(hostname)/O=server/ -nodes
        $ cd ../testca
        $ openssl ca -config openssl.cnf -in ../server/req.pem -out ../server/cert.pem -notext -batch -extensions server_ca_extensions
        $ cd ../server
        $ openssl pkcs12 -export -out keycert.p12 -in cert.pem -inkey key.pem -passout pass:MySecretPassword
         
  3.  Generating certificate and key for the client
    •  Apply following commands.
      • $ cd ..
        $ ls
        server testca
        $ mkdir client
        $ cd client
        $ openssl genrsa -out key.pem 2048
        $ openssl req -new -key key.pem -out req.pem -outform PEM -subj /CN=$(hostname)/O=client/ -nodes
        $ cd ../testca
        $ openssl ca -config openssl.cnf -in ../client/req.pem -out ../client/cert.pem -notext -batch -extensions client_ca_extensions
        $ cd ../client
        $ openssl pkcs12 -export -out keycert.p12 -in cert.pem -inkey key.pem -passout pass:MySecretPassword
         
  4. Configuring RabbitMQ Server
    To enable the SSL support in RabbitMQ, we need to provide to RabbitMQ the location of the root certificate, the server's certificate file, and the server's key. We also need to tell it to listen on a socket that is going to be used for SSL connections, and we need to tell it whether it should ask for clients to present certificates, and if the client does present a certificate, whether we should accept the certificate if we can't establish a chain of trust to it.

    For that we need to create file inside "/etc/rabbitmq". You have to name the file as "rabbitmq.config". Inside the file copy and paste following configuration.

    [
      {rabbit, [
         {ssl_listeners, [5671]},
         {ssl_options, [{cacertfile,"/path/to/testca/cacert.pem"},
                        {certfile,"/path/to/server/cert.pem"},
                        {keyfile,"/path/to/server/key.pem"},
                        {verify,verify_peer},
                        {fail_if_no_peer_cert,false}]}
       ]}
    ].
  5. Trust the Client's Root CA
    Use the following command.
    $ cat testca/cacert.pem >> all_cacerts.pem
     
    To validating certificate use below command.
     
    keytool -import -alias server1 -file /path/to/server/cert.pem -keystore /path/to/rabbitstore

    If you want study more about this configuration, go to this link. Now we have finished configuration in server side and created certificates. In my next blog, I will continue this blog by specifying CEP side Configuration. :)

Monday, July 18, 2016

Working with WSO2 RabbitMQ Inbound

I am writing this blog by considering you already have knowledge about inbound and RabbitMQ. If not please refer my previous blogs. It has brief idea about those.

In WSO2 RabbitMQ inbound, we use inbound as RabbitMQ consumer. It is event based inbound which polls only once to establish a connection with the remote server and then consumes events.  In here AMQP messaging protocol is used. AMQP is a wire-level messaging protocol that describes the format of the data that is sent across the network. If a system or application can read and write AMQP, it can exchange messages with any other system or application that understands AMQP regardless of the implementation language.

Steps to enable RabbitMQ Inbound 
  • Start the WSO2 Server by going <ESB_HOME>/bin by specifying this command sh ./wso2server.sh
  • Create  two simple sequences.  In my case I have created simple sequence names as TestIn and amqpErrorSeq with following configuration
    <?xml version="1.0" encoding="UTF-8"?>
    <sequence name="TestIn" onError="amqpErrorSeq" xmlns="http://ws.apache.org/ns/synapse">
        <log level="full"/>
        <drop/>
    </sequence>



    <?xml version="1.0" encoding="UTF-8"?>
    <sequence name="amqpErrorSeq" xmlns="http://ws.apache.org/ns/synapse">
        <log level="full"/>
        <drop/>
    </sequence>
  •  Go to inbound endpoints in Service Bus menu.
  • Click on Add Inbound endpoint. you will see the page like below.

  • Enter the name of the endpoint and select type as rabbitmq. Click on Next.
  • In the next page specify 

    • Sequence as TestIn.
    • Error Sequence as amqpErrorSeq. 
    • Suspend as false. We need to put as false to make inbound in enable mode. if we put true, the inbound is disabled.
    • Sequential as true.
    • Coordination as true.
    • rabbitmq.connection.factory as AMQPConnectionFactory
    • rabbitmq.server.host.name as localhost
    • rabbitmq.server.port as 5672. Here management console of rabbitmq is 15672. But here we have to mention as 5672.
    • rabbitmq.server.user.name as guest (In my case i am using guest account).
    • rabbitmq.server.password as guest (In my case i am using guest account).
    • rabbitmq.queue.name : specify a queue name.
  • rabbitmq.exchange.name : specify exchange name.
  • If you want to change anything in advanced options, click it and change it.
Thats all for the RabbitMq inbound. That means we have created consumer. For consuming events, we need to provide events. so i have created a sample java producer. That was given below. You can see the output of the message in ESB started terminal.

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
    private final static String QUEUE_NAME = "queue";
    private final static String contentEncoding = "utf-8";
    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setUsername("guest");
        factory.setPassword("guest");
        factory.setPort(5672);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        channel.exchangeDeclare("exchange", "direct", true);
        channel.queueBind(QUEUE_NAME, "exchange", "route");
        String message ="<m:placeOrder xmlns:m=\"http://services.samples\">" +
                "<m:order>" +
                "<m:price>100</m:price>" +
                "<m:quantity>20</m:quantity>" +
                "<m:symbol>RMQ</m:symbol>" +
                "</m:order>" +
                "</m:placeOrder>";
        // Populate the AMQP message properties
        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties().builder();
        builder.contentType("application/xml");
        builder.contentEncoding(contentEncoding);

        // Publish the message to exchange
        channel.basicPublish("exchange", QUEUE_NAME, builder.build(), message.getBytes());
        System.out.println(" [x] Sent '" + message + "'");
        channel.close();
        connection.close();
    }
}

The out is given below.



Wednesday, July 13, 2016

Working with own SOAP Receiver in WSO2 CEP

Hi all,

In this blog we are going to see from the beginning. Here I am doing one example from the start. You can do it same way for your scenario.

  • First we need to create stream. I created stream named as "soapStream". My created stream is given below.

  • Then we need to create a soap event receiver under Manage->Receivers in Management console. I created event receiver names as "soapTest". My created soap event receiver is given below.

  • Then we need to have publisher to view the output to check whether our input is going inside. I created a logger publisher named as "soapTestLogger" to view the output in terminal.

  • Now we have finished our initial steps. As we mentioned transport as http in Soap receiver which we created, we need to give http soap request. Here I used Postman (which is google chrome apps) to send the request. http address we have to use is http://localhost:9763/services/<ReceiverName>/receive. My receiver name is soapTest. so i used like http://localhost:9763/services/soapTest/receive. In header we have to mention Content-Type as application/xml. In body we have to give our events according to the stream. The body part i gave is given below.

    <soap:Envelope
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"
    soap:encodingStyle="http://www.w3.org/2003/05/soap-encoding"><soap:Body>
      <events>
        <event>
            <payloadData>
                <ID>70</ID>
                <Name>Test Data</Name>
            </payloadData>
        </event>
    </events>
    </soap:Body>

    </soap:Envelope>
The postman screen shot is given below.


 The output can view in the terminal(CEP started Terminal).

 Now we have finished using soap Receiver with Postman http request. Will see you in next blog. :)

Working with SOAP Receiver Sample in WSO2 CEP

Introduction to WSO2 CEP SOAP Receiver

Events are received by WSO2 CEP server using event receivers, which manage the event retrieval process. WSO2 CEP receives events via multiple transports in JSON, XML, Map, Text, and WSO2Event formats, and converts them into streams of canonical WSO2Events to be processed by the server. SOAP event receiver is used to receive events in XML format via HTTP, HTTPS, and local transports.

Doing the soap sample already available

WSO2 CEP has samples for every Event Receivers it has. You can run the sample very easily like below.
Steps
  • Start the CEP Server sample by going <CEP_HOME>/bin by specifying this command ./wso2cep-samples.sh -sn 0014
    We specify sample number as 0014 because of soap sample receiver is in that. you can view that by going <CEP_HOME>/samples/artifacts/0014/eventreceivers
The receiver is like this.

<?xml version="1.0" encoding="UTF-8"?>
<eventReceiver name="soapReceiver" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
    <from eventAdapterType="soap">
        <property name="transports">all</property>
    </from>
    <mapping customMapping="disable" type="xml"/>
    <to streamName="org.wso2.event.sensor.stream" version="1.0.0"/>
</eventReceiver> 
  • After starting the CEP server, you can see the stream named as "org.wso2.event.sensor.stream" and receiver "soapReceiver" in your CEP management console.
  • As the next step, you need to produce soap events which can be receive by CEP. There is sample java soap producer available in <CEP_HOME>/samples/producers/soap. So you just want to ant build it. For that in terminal, you have to go to above mentioned directory and use below Ant command.

    ant -Durl=http://localhost:9763/services/soapReceiver/receive -Dsn=0014

    Here http://localhost:9763/services/soapReceiver/receive means http location of the receiver. Then we specify the  the sample number. The xml format input data is taken from <CEP_HOME>/samples/artifacts/0014/soapReceiver.txt
  • After this ant command you can see the output in the terminal of CEP started like below.

 Thats All, now you have successfully ran the sample. In my next blog, we will focus on creating own Soap receiver, stream and sending soap request to that. Keep in touch :)