Sending messages to two services simultaneously usind Service Brokers - sql-server

could I send messages from one service to multiple service using service brokers?
Something like
BEGIN DIALOG CONVERSATION #dialog_handle
FROM SERVICE [SERVICE1]
TO SERVICE 'SERVICE2',**'SERVICE3'**
ON CONTRACT [MainContract]
Looking at the syntax, I do not think we could do this. What's the alternative?
Thanks and Regards
DEE

There is no publish-subscribe nor multicast built in into Service Broker. To send a message to multiple services you have to explicitly send it to each destination an o a separate dialog.
The typical solution is to send only one message from the application to a service that acts like a distributor. The distributor service receives this message and sends a copy of it to each interested service (Service2, Service3 etc). This way the application doesn't need to know upfront how many services it needs to send the message to, it just sends it to the distributor service.

Related

SQL Service Broker, send messages back to initiator

in my scenario, I want to have some services to be fixed (as in not needing to be updated) and as time goes by adding other services. (I'm using one DB instance, but it shouldn't matter in service broker)
I want to set up the fixed ones in a way to be able to send back a message to the initiator of any message in its queue without me changing its logic and procedures every time I add another service.
is it even possible or do I have to add more logic as new services are created?
If I'm understanding your question correctly, this is how Service Broker works by default. Which is to say that a conversation is between two parties (initiator and target). Once that conversation is established, either party can send messages on it and they will go to the other party. So, if you want to send a message back to the initiator, just send a message on the same conversation handle as the message was received on and you should be good to go.

User Destinations with Stomp, Spring Websockets, an External Broker with an External Consumer

My Question centers around this slide from one of Rossen Stoyanchev webinars.
When using a simpleBroker I can send messages to individual users with the /user/** destination format that is picked up in UserDestination and converted. I can also use it to send to a specific session, or all sessions of a specific user.
This is also possible when using an External Broker like ActiveMQ or RabbitMQ as long as the sender is also able to use /user/** or its helper annotations #SentToUser etc.
But, if I am not processing these messages locally and I have another consumer connected to the External Message Broker (Apache Camel for example) How do handle User specific messages and also reply at a user and session level?
If the other consumer is in the same JVM you can have the "brokerMessagingTemplate" bean injected and use it to send messages to user-prefixed destinations.
For 4.2 we plan to support user destinations in a deployment with multiple web application servers connected to an External broker (see https://jira.spring.io/browse/SPR-11620). So if the other consumer is in a different JVM, then you could declare the #EnableWebSocketMessageBroker setup in that JVM as well or you could simple extend AbstractMessageBrokerConfiguration if you don't need the WebSocket client bits.
HTH

how to send and recieve notification using WPF and WCF

I am using WPF and WCF for client server application. but i got a problem.
How to notify any update of client to other client.
Server(WCF)
Client1(WPF)
Client2(WPF)
if client1 enter any new record,immediatly notification send to client2 .
please suggest me best way to this complete task.
Thanks..
We have achieved such a requirement by using WCF Duplex Services. You can find enough information by googling about implementing a duplex service.
Basically;
clients send a client identifier (uniquely generated for each client) while registering to duplex service.
when WCF service updates data, pushes an update notification (including the notification source's client identifier) to all the registered clients
clients check for the originator's identifier when they got a notification. Discarding notifications caused by itself.
A few notes:
You can include everything about the updated data inside pushed notification payload to understand the change type or entity type.
Different bindings supported by duplex services. Usage of nettcpbinding is suggested if clients and service are in the same network and .net dependency is not a problem. You can find more information about support binding types from here or here.

Reconnecting WCF clients after a service receive timeout has occured

I have a WCF service which I host inside a WFP application, which acts as one of the clients of service as well. There is one more WPF app which acts as another client for service. After a timeout occurs and clients get disconnected, What is the proper way to clean up resources and connect the clients again. I am trying to create new proxies but I am not able to use them for communication. I know I can increase the recieve timeout on service but I need my clients to be able to communicate always not just for long enough. I have also tried continously sending a message to service at interval but that's something I don't want to go for. What approach is best for continous communication between clients and service? My service might need to be connected to clients for months or may be years.
Any help will be of great value.
Thanks in advance.
You can catch the CommunicationException or something like that and then restore the channel.

WCF: how to ensure if an updated was successful?

I have a WCF service, hosted in a win form application, that receive the requests from the clients. One of this requests, is update the stock of the items.
Well, my idea is to use a client to send to the WCF service the new amount of items, then the service use Entity Framework 4.1 to update the database with the new stock.
How the service is duplex, when the services has finished the update, it sends a message to the client to notify that the operations is successful. That's if there is no problems.
However, I have a question. It's possible that the client send the command to the service to update the stock. The service receive the command correctly, but before the operation is finished, the client lost the connection with the service, so the services can't send to the client the status of the operation, so the user does not know if it's all ok or not.
My second question has the same logic, but with the WCF service. It's possible that the WCF service is installed in other computer different to the computer in which is installed the database. So it's possible that the WCF services send correctly the command to the database, but before the database notify that the operation is successful, the WCF service lost the connection, so it never receive a response from the database but the operation is successful. How can the user know if the operation is ok or not?
So my question is, in WCF, how can I be sure that critical operations are successful or not?
Thanks.
Daimroc.

Resources