source: trunk/src/main/java/omq/client/proxy/MultiProxymq.java @ 77

Last change on this file since 77 was 77, checked in by stoda, 11 years ago

ParameterQueues? changed, added some properties to modify the queues

File size: 2.2 KB
Line 
1package omq.client.proxy;
2
3import java.lang.reflect.InvocationHandler;
4import java.lang.reflect.Method;
5import java.util.Properties;
6
7import org.apache.log4j.Logger;
8
9import com.rabbitmq.client.AMQP.BasicProperties;
10
11import omq.common.broker.Broker;
12import omq.common.message.Request;
13import omq.common.util.ParameterQueue;
14import omq.common.util.Serializer;
15
16/**
17 * TODO Aquesta classe s'eliminarà tant bon punt es faci un proxymq més
18 * intel·ligent
19 *
20 * @author sergi
21 *
22 */
23public class MultiProxymq implements InvocationHandler {
24        private static final Logger logger = Logger.getLogger(MultiProxymq.class.getName());
25        private static final String multi = "multi#";
26
27        private String uid;
28        private Broker broker;
29        private Serializer serializer;
30        private String replyQueueName;
31        private String exchange;
32        private static final String routingkey = "";
33        private transient String serializerType;
34
35        public MultiProxymq(String uid, Class<?> clazz, Broker broker) throws Exception {
36                this.uid = uid;
37                this.broker = broker;
38                serializer = broker.getSerializer();
39
40                Properties env = broker.getEnvironment();
41                replyQueueName = env.getProperty(ParameterQueue.RPC_REPLY_QUEUE);
42                exchange = multi + uid;
43                serializerType = env.getProperty(ParameterQueue.PROXY_SERIALIZER, Serializer.JAVA);
44        }
45
46        @Override
47        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
48                String methodName = method.getName();
49                String corrId = java.util.UUID.randomUUID().toString();
50                boolean multi = true;
51
52                Request request = Request.newAsyncRequest(corrId, methodName, args, multi);
53
54                // Add the correlation ID and create a replyTo property
55                BasicProperties props = new BasicProperties.Builder().appId(uid).correlationId(corrId).replyTo(replyQueueName).type(serializerType).build();
56
57                byte[] bytesRequest = serializer.serialize(serializerType, request);
58                broker.getChannel().basicPublish(exchange, routingkey, props, bytesRequest);
59
60                logger.debug("Proxymq: " + uid + " invokes " + methodName + ", corrID" + corrId + ", exchange: " + exchange + ", replyQueue: " + replyQueueName
61                                + ", serializerType: " + serializerType + ", multi call: " + request.isMulti() + ", async call: " + request.isAsync());
62
63                return null;
64        }
65
66}
Note: See TracBrowser for help on using the repository browser.