Simples Assim

How to Setup Load Balancing in Tomcat with mod_proxy_balancer

leave a comment »

1) Create the <Apache Install Dir>/conf.d/mod_proxy_balancer.conf file:

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule status_module modules/mod_status.so

<Location /balancer-manager>
  SetHandler balancer-manager
</Location>

<Proxy balancer://sample-balancer>
  BalancerMember ajp://node1:8009
  BalancerMember ajp://node2:8009
  ProxySet scolonpathdelim=On
  ProxySet stickysession=JSESSIONID
</Proxy>

ProxyPass /sample balancer://sample-balancer

2) Change the <Tomcat Install Dir>/conf/server.xml file in each node:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  ...
  <Service>
    ...
    <Engine jvmRoute="node1">
      ...
    </Engine>
  </Service>
</Server>

3) Start Apache, and then Tomcat.

About these ads

Written by Fernando Ribeiro

September 16, 2014 at 8:35 am

How to Setup a Tomcat Cluster

leave a comment »

Dynamic Discovery

1) Change the <Tomcat Install Dir>/conf/server.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  ...
  <Service>
    ...
    <Engine>
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      ...
    </Engine>
  </Service>
</Server>

2) Start Tomcat.

Static Discovery

1) Change the <Tomcat Install Dir>/conf/server.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  ...
  <Service>
    ...
    <Engine>
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelStartOptions="3">
        <Channel className="org.apache.catalina.tribes.group.GroupChannel">
          <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member className="org.apache.catalina.tribes.membership.StaticMember" port="4000" host="host1" uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}" />
            <Member className="org.apache.catalina.tribes.membership.StaticMember" port="4000" host="host2" uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2}" />
          </Interceptor>
        </Channel>
      </Cluster>
      ...
    </Engine>
  </Service>
</Server>

2) Start Tomcat.

You can find more details here.

Written by Fernando Ribeiro

September 16, 2014 at 8:13 am

Posted in Technology

Tagged with ,

Bug in Renjin 0.7.0-RC7

leave a comment »

I can’t access Java static fields.

https://github.com/bedatadriven/renjin/issues/69

Written by Fernando Ribeiro

September 1, 2014 at 3:01 pm

Posted in Software

Tagged with ,

How to Create a Multicast Client/Server with Apache Tribes

leave a comment »

Client

import static java.lang.System.out;

import java.io.Serializable;

import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.ChannelListener;
import org.apache.catalina.tribes.Member;
import org.apache.catalina.tribes.group.GroupChannel;

public final class TribesClient {

  public static void main(final String[] args) throws Exception {
    final Channel chan = new GroupChannel();

    chan.start(Channel.DEFAULT);

    chan.addChannelListener(new ChannelListener() {

      public boolean accept(final Serializable msg, final Member sender) {
        return true;
      }

      public void messageReceived(final Serializable msg, final Member sender) {
        out.println(msg);
      }

    });
  }

}

Server

import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.group.GroupChannel;

public final class TribesServer {

  public static void main(final String[] args) throws Exception {
    final Channel chan = new GroupChannel();

    chan.start(Channel.DEFAULT);

    while (true)

      if (chan.hasMembers())
        chan.send(chan.getMembers(), "Simples Assim", Channel.SEND_OPTIONS_MULTICAST);

  }

}

Written by Fernando Ribeiro

August 31, 2014 at 12:53 am

How to Receive a Message from an Apache ActiveMQ Topic with Tcl/Java

leave a comment »

W/o Durability

package require java

java::import javax.jms.Connection
java::import javax.jms.ConnectionFactory
java::import javax.jms.Destination
java::import javax.jms.Message
java::import javax.jms.MessageProducer
java::import javax.jms.Session
 
java::import org.apache.activemq.ActiveMQConnectionFactory
 
set connFactory [java::new ActiveMQConnectionFactory tcp://localhost:61616]
 
set conn [$connFactory createConnection]
 
set sess [$conn createSession false [java::field Session AUTO_ACKNOWLEDGE]]

set dest [$sess createTopic SampleTopic]
 
set cons [$sess createConsumer $dest]

$conn start

set msg [$cons receive]
 
puts $msg
 
$conn close

W/ Durability

package require java

java::import javax.jms.Connection
java::import javax.jms.ConnectionFactory
java::import javax.jms.Destination
java::import javax.jms.Message
java::import javax.jms.MessageProducer
java::import javax.jms.Session
 
java::import org.apache.activemq.ActiveMQConnectionFactory
 
set connFactory [java::new ActiveMQConnectionFactory tcp://localhost:61616]
 
set conn [$connFactory createConnection]

$conn setClientID SampleClient
 
set sess [$conn createSession false [java::field Session AUTO_ACKNOWLEDGE]]

set dest [$sess createTopic SampleTopic]
 
set cons [$sess createDurableSubscriber $dest SampleSubscription]

$conn start

set msg [$cons receive]
 
puts $msg
 
$conn close

Written by Fernando Ribeiro

August 24, 2014 at 7:30 pm

How to Receive a Message from an Apache ActiveMQ Queue with Tcl/Java

leave a comment »

package require java

java::import javax.jms.Connection
java::import javax.jms.ConnectionFactory
java::import javax.jms.Destination
java::import javax.jms.Message
java::import javax.jms.MessageProducer
java::import javax.jms.Session
 
java::import org.apache.activemq.ActiveMQConnectionFactory
 
set connFactory [java::new ActiveMQConnectionFactory tcp://localhost:61616]
 
set conn [$connFactory createConnection]
 
set sess [$conn createSession false [java::field Session AUTO_ACKNOWLEDGE]]

set dest [$sess createQueue SampleQueue]
 
set cons [$sess createConsumer $dest]

$conn start

set msg [$cons receive]
 
puts $msg
 
$conn close

Written by Fernando Ribeiro

August 24, 2014 at 7:29 pm

How to Send a Message to an Apache ActiveMQ Topic with Tcl/Java

leave a comment »

package require java

java::import javax.jms.Connection
java::import javax.jms.ConnectionFactory
java::import javax.jms.Destination
java::import javax.jms.Message
java::import javax.jms.MessageProducer
java::import javax.jms.Session
 
java::import org.apache.activemq.ActiveMQConnectionFactory
 
set connFactory [java::new ActiveMQConnectionFactory tcp://localhost:61616]
 
set conn [$connFactory createConnection]
 
set sess [$conn createSession false [java::field Session AUTO_ACKNOWLEDGE]]

set dest [$sess createTopic SampleTopic]
 
set prod [$sess createProducer $dest]
 
set msg [$sess createTextMessage Simples Assim]
 
$prod send $msg
 
$conn close

Written by Fernando Ribeiro

August 24, 2014 at 7:29 pm

Follow

Get every new post delivered to your Inbox.

Join 1,219 other followers