سؤال

I have some requirement for Live chat for my company Website. My main requirement is, There are 5 agents in my office which responds to customer queries. At a time many Customer can ask questions, Say Customer A ask Question, In that case I have to check which Agent is Free and dedicate 1 Free Agent to that(A) Customer. Similarly for all the other Customers dedicated agent should be allocated and once all the agent is busy then further Customer Request should be Queued.

After completing customer Queries, Agent should be Free to handle Queued Customer.

I came to know that Atmosphere Framework provide such functionality easily and gave my hands on Atmosphere (atmosphere-jquery-pubsub-1.0.18.war).

I am able to run a program but it is acting as Group Chat i.e If written "Hi", then it get Broadcasted to all the Browsers connected instead I need as Agent-Customer case i.e One to One dedicated communication.

@Path("/pubsub/{topic}")
public class JQueryPubSub
{

  @PathParam("topic")
  private Broadcaster topic;

  @GET
  public SuspendResponse<String> subscribe()
  {
    return new SuspendResponse.SuspendResponseBuilder().broadcaster(this.topic).outputComments(true).addListener(new EventsLogger()).build();
  }

  @POST
  @Broadcast
  @Produces({"text/html;charset=ISO-8859-1"})
  public Broadcastable publish(@FormParam("message") String message)
  {
    return new Broadcastable(message, "", this.topic);
  }
}

What I tried to achieve same functionality is, I took 1 HashTable, in which I add AtmosphereResource based on Filtered IP then I tried to assign Customer to Admin present in HashTable.

I am able to achieve put it became very complex code and I think there would be simple way to do it.

هل كانت مفيدة؟

المحلول

I think you are subscribing all pairs "customer-agent" to a single topic.

Try encoding customer id and agent id in topic name.

Or you can have separate endpoints for messages directed to users and agents. Then agent subscribes(and publishes) to topic "/pubsub/customer/{customerId}", customer to "/pubsub/agent/{agentId}".

Or just use a single entity "/pubsub/user/{userId}" (if customer ids and agent ids may overlap then encode type of entity in userId, like agent123/customer123).

In both cases you will have to setup disposal of broadcasters: Preventing Out of Memory, since they are created on the fly.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top