public void TestInit() { this.storageAccount = CloudStorageAccount.Parse(storageConnectString); Debug.Print("connect emulator successfully!"); clientId = Guid.NewGuid().ToString(); this.sessionPersist = new AzureQueuePersist(username, sessionId, clientId, storageConnectString); this.requestQueue = this.storageAccount.CreateCloudQueueClient() .GetQueueReference(MakeQueuePath(sessionId, clientId, true)); this.responseTable = this.storageAccount.CreateCloudTableClient() .GetTableReference(MakeTablePath(sessionId, clientId)); this.blobContainer = this.storageAccount.CreateCloudBlobClient() .GetContainerReference(MakeQueuePath(sessionId, clientId, true)); this.pendingQueue = this.storageAccount.CreateCloudQueueClient() .GetQueueReference(MakePendingPath(sessionId, clientId)); this.CallbackIsCalled = false; this.IsExpected = false; }
/// <summary> /// cleanup the stale persisted data for the sessions that related jobs are purged by the scheduler. /// </summary> /// <param name="persistName">the persist name.</param> /// <param name="isStaleSessionCallback">the calback function to judge whether a session is stale.</param> public static async Task CleanupStalePersistedData(string persistName, IsStaleSessionCallback isStaleSessionCallback, string connectString) { ParamCheckUtility.ThrowIfNull(isStaleSessionCallback, "isStaleSessionCallback"); if (!string.IsNullOrEmpty(persistName)) { if (persistName.Trim().Equals("AzureQueue", StringComparison.OrdinalIgnoreCase)) { BrokerTracing.TraceInfo( "[BrokerQueueFactory] .CleanupStalePersistedData: cleaning up stale data in AzureQueue"); await AzureQueuePersist .CleanupStaleMessageQueue(isStaleSessionCallback, connectString); } else { throw new ArgumentOutOfRangeException("persistName", persistName + ", which persistence is not supported."); } } }
public BrokerQueue GetPersistQueueByClient(string clientId, string userName, out bool isNewCreate) { BrokerTracing.TraceInfo($"[GetPersistQueueByClient] username:{userName}, sessionid:{this.sessionId}, client:{clientId}"); isNewCreate = false; if (string.IsNullOrEmpty(clientId)) { clientId = BrokerQueueFactory.defaultClientId; } BrokerQueue brokerQueue = null; lock (this.clientBrokerQueueDic) { this.clientBrokerQueueDic.TryGetValue(clientId, out brokerQueue); } if (brokerQueue == null) { lock (this.thisLockObj) { lock (this.clientBrokerQueueDic) { this.clientBrokerQueueDic.TryGetValue(clientId, out brokerQueue); } if (brokerQueue == null) { ISessionPersist sessionPersist = null; if (string.IsNullOrEmpty(this.persistName)) { sessionPersist = new MemoryPersist(userName, this.sessionId, clientId); brokerQueue = new BrokerPersistQueue( this.brokerQueueDispatcher, this.persistName, this.sessionId, clientId, sessionPersist, 1, // no request cache // no request cache 1, // no response cache // no response cache 0, // no timeout // no timeout false, // no in-memory cache this.sharedData, this); this.brokerQueueDispatcher.AddBrokerQueue(brokerQueue, null); } else { ParamCheckUtility.ThrowIfNull(this.sharedData.BrokerInfo.AzureStorageConnectionString, "StorageConnectString"); sessionPersist = new AzureQueuePersist(userName, this.sessionId, clientId, this.sharedData.BrokerInfo.AzureStorageConnectionString); isNewCreate = sessionPersist.IsNewCreated; brokerQueue = new BrokerPersistQueue( this.brokerQueueDispatcher, this.persistName, this.sessionId, clientId, sessionPersist, BrokerQueueConstants.DefaultThresholdForRequestPersist, BrokerQueueConstants.DefaultThresholdForResponsePersist, BrokerQueueConstants.DefaultMessagesInCacheTimeout, isNewCreate, // need in-memory quick cache for newly-created durable queue // need in-memory quick cache for newly-created durable queue this.sharedData, this); // // For an existing durable queue, if EndOfMessage is not received, or there are requests waiting to be processed, // then schedule the broker queue for dispatching; // for an newly created durable queue, it will be added to brokerQueueDispatcher when BrokerQueuePersist.Flush // is called (with quick cache filled), so no need to call AddBrokerQueue here (bug #21453) // if (!isNewCreate && (!brokerQueue.EOMReceived || sessionPersist.RequestsCount > 0)) { this.brokerQueueDispatcher.AddBrokerQueue(brokerQueue, null); } } lock (this.clientBrokerQueueDic) { this.clientBrokerQueueDic.Add(clientId, brokerQueue); } } } } // Bug 6313: Check the user name ThrowIfUserNameDoesNotMatch(brokerQueue, userName); return(brokerQueue); }