protected void SetUp()
 {
     mocks = new Mockery();
     mockConnectionFactory    = mocks.NewMock <IConnectionFactory>();
     mockConnection           = mocks.NewMock <IConnection>();
     mockSession              = mocks.NewMock <ISession>();
     mockDestination          = mocks.NewMock <IDestination>();
     mockProducer             = mocks.NewMock <IMessageProducer>();
     testActiveMqRemoteSender = new ActiveMqRemoteSender(connectUriName, queueName, messageFilter, new ConsoleApplicationLogger(LogLevel.Warning, '|', "  "), new NullMetricLogger(), mockConnectionFactory, mockConnection, mockSession, mockDestination, mockProducer);
 }
        //------------------------------------------------------------------------------
        //
        // Method: MainViewRemoteAdapterActiveMQ (constructor)
        //
        //------------------------------------------------------------------------------
        /// <summary>
        /// Initialises a new instance of the SampleApplication2.MainViewRemoteAdapterActiveMQ class.
        /// </summary>
        /// <param name="connectUriName">The uniform resource name of the ActiveMq broker to connect to.</param>
        /// <param name="outgoingQueueName">The name of the ActiveMq queue to use for outgoing method calls.</param>
        /// <param name="incomingQueueName">The name of the ActiveMq queue to use for incoming method calls.</param>
        /// <param name="requestFilter">The message filter to use for method invocation requests (i.e. calls).</param>
        /// <param name="responseFilter">The message file to use for method invocation responses (i.e. return values).</param>
        public MainViewRemoteAdapterActiveMQ(string connectUriName, string outgoingQueueName, string incomingQueueName, string requestFilter, string responseFilter)
        {
            // Setup objects for sending method invocations
            outgoingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap());
            outgoingSender           = new ActiveMqRemoteSender(connectUriName, outgoingQueueName, requestFilter);
            outgoingReceiver         = new ActiveMqRemoteReceiver(connectUriName, outgoingQueueName, responseFilter, 200);
            methodInvocationSender   = new MethodInvocationRemoteSender(outgoingMethodSerializer, outgoingSender, outgoingReceiver);

            // Setup objects for receiving method invocations
            incomingMethodSerializer = new MethodInvocationSerializer(new SerializerOperationMap());
            incomingSender           = new ActiveMqRemoteSender(connectUriName, incomingQueueName, responseFilter);
            incomingReceiver         = new ActiveMqRemoteReceiver(connectUriName, incomingQueueName, requestFilter, 200);
            methodInvocationReceiver = new MethodInvocationRemoteReceiver(incomingMethodSerializer, incomingSender, incomingReceiver);
            // Hook the 'MethodInvocationReceived' event on the receiver up to the local method which handles recieving method invocations
            methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation);
        }
예제 #3
0
        static void Main(string[] args)
        {
            // Setup connection parameters for ActiveMQ
            const string connectUri                 = "activemq:tcp://localhost:61616?wireFormat.maxInactivityDuration=0";
            const string queueName                  = "FromJava";
            const string requestQueueFilter         = "Request";
            const string responseQueueFilter        = "Response";
            const int    receiverConnectLoopTimeout = 200;

            // Setup method invocation receiver
            ActiveMqRemoteSender           activeMqSender           = new ActiveMqRemoteSender(connectUri, queueName, responseQueueFilter);
            ActiveMqRemoteReceiver         activeMqReceiver         = new ActiveMqRemoteReceiver(connectUri, queueName, requestQueueFilter, receiverConnectLoopTimeout);
            MethodInvocationSerializer     methodSerializer         = new MethodInvocationSerializer(new SerializerOperationMap());
            MethodInvocationRemoteReceiver methodInvocationReceiver = new MethodInvocationRemoteReceiver(methodSerializer, activeMqSender, activeMqReceiver);

            methodInvocationReceiver.MethodInvocationReceived += new MethodInvocationReceivedEventHandler(ReceiveMethodInvocation);

            try
            {
                // Connect to ActiveMQ
                activeMqSender.Connect();
                activeMqReceiver.Connect();
                // Start receiving method invocations
                methodInvocationReceiver.Receive();
                Console.WriteLine("Waiting for incoming method calls...");
                Console.WriteLine("Press [ENTER] to cancel.");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("An exception occurred");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
            finally
            {
                // Stop receiving, disconnect, and dispose
                methodInvocationReceiver.CancelReceive();
                activeMqReceiver.CancelReceive();
                activeMqReceiver.Disconnect();
                activeMqSender.Disconnect();
                activeMqReceiver.Dispose();
                activeMqSender.Dispose();
            }
        }