Pages

Subscribe:

Ads 468x60px

Featured Posts

Thursday, March 17, 2016

How to Enable Asynchronous Logging with C5

In this post we are going to explore on how to enable asynchronous logging on C5 based servers. More on asynchronous logging can be found here.

1. Copy the disrupter dependency to the /osgi/plugins folder. You can get the disrupter OSGi bundle from here.
2. Edit launch.properties the /bin/bootstrap/org.wso2.carbon.launcher-5.1.0.jar and add the disrupter jar to the initial bundles list.
carbon.initial.osgi.bundles=\
  file\:plugins/org.eclipse.osgi.services_3.4.0.v20140312-2051.jar@1\:true,\
  file\:plugins/disruptor-3.2.0.jar@2\:true,\
  file\:plugins/org.ops4j.pax.logging.pax-logging-api_1.8.4.jar@2\:true,\
  file\:plugins/org.ops4j.pax.logging.pax-logging-log4j2_1.8.4.jar@2\:true,\
  file\:plugins/org.eclipse.equinox.simpleconfigurator_1.1.0.v20131217-1203.jar@3\:true

3. Set the org.ops4j.pax.logging.log4j2.async to true in the pax logging parameters.

4. Add the async loggers to the log4j2.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<Configuration>
    <Appenders>
 <RandomAccessFile name="RandomAccessFile" fileName="${sys:carbon.home}/logs/carbon.log" immediateFlush="false" append="false">
        <PatternLayout>
          <Pattern>[%d] %5p {%c} - %m%ex%n</Pattern>
        </PatternLayout>
     </RandomAccessFile>
        <Console name="CARBON_CONSOLE" target="SYSTEM_OUT">
            <PatternLayout pattern="[%d] %5p {%c} - %m%ex%n"/>
        </Console>
        
    </Appenders>
    <Loggers>

 <AsyncLogger name="com.foo.Bar" level="trace" includeLocation="true">
      <AppenderRef ref="RandomAccessFile"/>
    </AsyncLogger>

        <Root level="debug">
     <AppenderRef ref="RandomAccessFile"/>
            <AppenderRef ref="CARBON_CONSOLE"/>
        </Root>
    </Loggers>
</Configuration>

That's it now you have enabled the asynchronous logging with C5.

Wednesday, February 10, 2016

MSF4J :WSO2 Microservices Framework for Java to be Unleashed

WSO2 MSF4J Quick Start Guide

WSO2 recently started implementing a Micro Services Server and finally it will be available as a Micro Services Framework 4 Java. In this post we are going to learn and understand how fast you can write a Micro service in a couple of steps.

So lets get start then.
Prerequisites.
1. JDK 1.8
2. Maven 3.2.0 or above
  1. Clone the git repository and you have to build it, since it's not still released.
git clone https://github.com/wso2/msf4j.git

    2. Create the project using the archetype

mvn archetype:generate 
-DarchetypeGroupId=org.wso2.msf4j 
-DarchetypeArtifactId=msf4j-microservice 
-DarchetypeVersion=1.0.0-SNAPSHOT 
-DgroupId=org.wso2.carbon -DartifactId=Hello-Service 
-Dversion=1.0-SNAPSHOT 
-Dpackage=org.wso2.carbon 
-DserviceClass=HelloService

    3. Open the project using your IDE. and change the HelloService.java as follows. We only implement the GET here.

package org.wso2.carbon;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

/**
 * This is the Microservice resource class.
 * See <a href="https://github.com/wso2/msf4j#getting-started">https://github.com/wso2/msf4j#getting-started</a>
 * for the usage of annotations.
 *
 * @since 1.0-SNAPSHOT
 */
@Path("/service")
public class HelloService {

    @GET
    @Path("/{name}")
    @Produces({"application/json", "text/xml"})
    public String get(@PathParam("name")String name) {
        return "Hello " + name;
    }
}

    4. Run the program from your IDE. if it's successfully started you'll get a similar log.

2016-02-10 21:52:01 INFO  MicroservicesRegistry:76 - Added microservice: org.wso2.carbon.HelloService@6aa8ceb6
2016-02-10 21:52:01 INFO  NettyListener:56 - Starting Netty Http Transport Listener
2016-02-10 21:52:01 INFO  NettyListener:80 - Netty Listener starting on port 8080
2016-02-10 21:52:01 INFO  MicroservicesRunner:122 - Microservices server started in 197ms

    5. Now lets invoke the service using curl command to test it..

curl -v -X GET http://localhost:8080/service/Aruna
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /service/aruna HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Content-Length: 13
< Connection: keep-alive
< 
* Connection #0 to host localhost left intact
"Hello Aruna"

So that's it folks, you have implemented your first micro service and just invoked it!!!

So if you are interested, please checkout our git documentation for more features, performance comparisons. And if you have any questions don't forget to drop a mail to dev@wso2.org or architecture@wso2.org

See you soon with another interesting blog post... :)