public string Send(string message)
        {
            Trace.TraceInformation($"Message received:  {message}\n");
            //return "Message succesfully sent.\n";

            //salji instanci ciji je id za 1 manji od trenutne
            var brotherInstances = RoleEnvironment.Roles["WorkerRole1"].Instances;

            int index = GetIndex(RoleEnvironment.CurrentRoleInstance.Id) - 1;  //umanjen za 1

            if (index < 0)
            {
                index = brotherInstances.Count - 1;
            }
            string adresa = "";

            foreach (var item in brotherInstances)
            {
                Trace.WriteLine($"***Calling node on {item.InstanceEndpoints.ToString()}\n\n");
                if (index == GetIndex(item.Id))
                {
                    adresa = $"net.tcp://{item.InstanceEndpoints[endpointName].IPEndpoint}/{endpointName}";
                    break;
                }
            }

            //slanje odredjenoj instanci:
            ChannelFactory <IForward> factory = new ChannelFactory <IForward>(binding,
                                                                              new EndpointAddress(adresa));

            proxy = factory.CreateChannel();
            proxy.Send(message);
            return("Uspesno prosledjeno instanci za id-em umanjenim za 1\n");
        }
        public string Send(string message)
        {
            Trace.TraceInformation($"Message received:  {message}\n");
            //return "Instanca u workerRoli1 uspesno primila poruku.\n";

            //salji svim instancama WorkerRole2 istovremeno
            var    instancesOfSecondRole = RoleEnvironment.Roles["WorkerRole2"].Instances;
            string adresa = "";

            foreach (var el in instancesOfSecondRole)
            {
                adresa = $"net.tcp://{el.InstanceEndpoints[endpointName].IPEndpoint}/{endpointName}";
                ChannelFactory <IForward> factory = new ChannelFactory <IForward>(binding,
                                                                                  new EndpointAddress(adresa));
                proxy = factory.CreateChannel();
                Task t = Task.Factory.StartNew(() =>
                {
                    proxy.Send(message);
                });

                //Trace.TraceInformation($"Task completed at {DateTime.Now}");
            }
            Task.WaitAll();

            return($"Poruka uspesno poslata instancama u WorkerRole2\n");
        }
Пример #3
0
        static void Main(string[] args)
        {
            //client salje string (poruku)
            string message = "";
            string odgovor = "";

            do
            {
                Console.WriteLine("Unesi poruku: ");
                message = Console.ReadLine();

                Connect();

                odgovor = proxy.Send(message);
                Console.WriteLine(odgovor);
            } while (message != "");

            Console.ReadLine();
        }