1

I need to integrate outlook corporate emails in CRM. For this is use java EWS API. I read microsoft documentation of EWS but I still have some questions, maybe someone can help. First I need to connect with ExchangeService:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2)
ExchangeCredentials credentials = new WebCredentials(email, password)
service.setCredentials(credentials)
service.autodiscoverUrl(email, new RedirectionUrlCallback())

For this connection to be established takes about 5 seconds, it is pretty much for a real time application. I'm ok to create this connection only one time and then reuse it but as I read ExchangeService is not thread safe, so I need to create a connection to send an email, then close the connection, then create again a new connection when I need to subscribe for notifications etc.

Is there another approach to deal with exchange service connection?

I tried to reuse the exchange service connection and I get this:

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. Connection is still allocated

Another question is about streaming subscription that enables client applications to discover events that occur in the Exchange store, I think this is the right fit method for me:

StreamingSubscriptionConnection conn = new   StreamingSubscriptionConnection(service, 30);
conn.addSubscription(subscription);
conn.addOnNotificationEvent(new SubscriptionConnectionListener());
conn.addOnDisconnect(this);
conn.open();

So first I need the connection to the ExchangeService to be opened, and then I need to open the SubscriptionConnection. Because SubscriptionConnectionListener should wait all the time for new events I don't close the connection. Connection expiry after 30 minutes. I can catch the expiry connection and opened again. How to deal with that when 1000 users have opened subscription connections with their exchange service, basically if the subscription connection remains opened for new events also the exchange service connection used for subscription should stay alive.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
aelve
  • 119
  • 1
  • 10
  • "Please tell me if there is another approach to deal with exchange service connection" Guard the connection with a mutex, so only one thread can access it at once; use a `ThreadLocal` so each thread has its own connection. – Andy Turner Jun 02 '16 at 09:58
  • Ok, I have multiple tenants. Let's say currently tenant A have 5 users. Ther user 1 want to send an email, and also user 1 should be notified when he receive an email. For this I need 2 connection to the exchange service. First to send the email, and second to listen to the NewEmail event. Send email and receive emails are on different controller/services, this means different threads. After send email I can close the ews connection, but to receive emails the connection should be opened all the time. To send an email took 5+ seconds because the connection on ews. Is this the right approach ? – aelve Jun 02 '16 at 10:42

0 Answers0