-
1. Re: Transform + Divert usage question
clebert.suconic Dec 5, 2011 12:53 PM (in response to shergill)It seems like you need multiple Diverts and one Transformer per target address?
-
2. Re: Transform + Divert usage question
jdahlbom Dec 8, 2011 1:57 AM (in response to shergill)Clebert has it right, below is my implementation:
AbstractTransformer
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.cluster.Transformer;
public abstract class AbstractTransformer implements Transformer {
protected abstract String getMessageType();
@Override
public ServerMessage transform(ServerMessage message) {
message.putStringProperty(TransformationConstants.IDENTIFYING_PARAMETER, getMessageType());
return message;
}
}
RequestEmailTransformer:
public class RequestEmailTransformer extends AbstractTransformer {
@Override
protected String getMessageType() {
return TransformationConstants.TYPE_REQUEST_EMAIL;
}
}
TransformationConstants:
public final class TransformationConstants {
public static final String IDENTIFYING_PARAMETER = "messageType";
public static final String TYPE_REQUEST_EMAIL = "requestEmail";
}
I bundle all the transformers into a jar and deploy that separately.
hornetq-configuration.xml on the sending side of the bridge, which also applies the transformations:
<diverts>
<divert name="email-divert">
<address>jms.queue.requestEmail</address>
<forwarding-address>jms.queue.storeAndForward</forwarding-address>
<transformer-class-name>
my.package.RequestEmailTransformer
</transformer-class-name>
<exclusive>true</exclusive>
</divert>
</diverts>
hornetq-configuration.xml on the receiving side of the bridge (in jboss 6.1):
<diverts>
<divert name="email-divert">
<address>jms.queue.receiverQueue</address>
<forwarding-address>jms.queue.requestEmail</forwarding-address>
<filter string="messageType='requestEmail'"/>
<exclusive>true</exclusive>
</divert>
</diverts>
EDIT: Added diverts with transformations.
-
3. Re: Transform + Divert usage question
shergill Dec 7, 2011 2:23 PM (in response to jdahlbom)Where are you specifying the transform? I dont see it in your divert configuration. If you were to do it there; do you use the 'Abstract Transformer'?
-
4. Re: Transform + Divert usage question
shergill Dec 7, 2011 6:15 PM (in response to shergill)My other option is to rebuild HornetQ from source and add this line in the DivertBindings.java
public void route(final ServerMessage message, final RoutingContext context) throws Exception
{
// add this line
message.setProperty("DIVERTNAME", routingName);
divert.route(message, context);
}
-
5. Re: Transform + Divert usage question
jdahlbom Dec 8, 2011 2:01 AM (in response to shergill)Oops, looks like I pasted the wrong end of the bridge configuration.
Below is the correct one - also added to my original reply.
hornetq-configuration.xml on the sending side of the bridge, which also applies the transformations:
<diverts>
<divert name="email-divert">
<address>jms.queue.requestEmail</address>
<forwarding-address>jms.queue.storeAndForward</forwarding-address>
<transformer-class-name>
my.package.RequestEmailTransformer
</transformer-class-name>
<exclusive>true</exclusive>
</divert>
</diverts>
AbstractTransformer is not directly used anywhere (obviously, it being abstract), it merely exists to avoid duplicating attribute adding code in my several near-identical transformers (one for every queue).
Adding your own diverts to HornetQ binaries is wrong, not to mention unmaintainable.
-
6. Re: Transform + Divert usage question
shergill Dec 9, 2011 7:03 PM (in response to shergill)Can someone tell me if there is a problem with doing what i'm doing here.
I've made this change in the 2.2.5 source (from SVN) and compiled a build. It does exactly what I wanted to do.. but I would like to get some feedback from the developers if this is ok or not.
The change is in 'DivertBinding.java'.
public void route(final ServerMessage message, final RoutingContext context) throws Exception
{
message.putStringProperty(SimpleString.toSimpleString("ROUTINGNAME"), getRoutingName());
divert.route(message, context);
}