2014-09-09 4 views
2

나는 푸른 서비스 버스에 주제에 메시지를 추진하기 위해 노력하고있어,하지만 난 그렇게 할 때, 나는 다음과 같은 예외가 얻을 :푸른 서비스 버스 - 지원되는 유일한 IsolationLevel은 'IsolationLevel.Serializable'이다

System.InvalidOperationException was unhandled by user code 
    HResult=-2146233079 
    Message=The only supported IsolationLevel is 'IsolationLevel.Serializable'. 
    Source=Microsoft.ServiceBus 
    StackTrace: 
    Server stack trace: 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpResourceManager.EnlistAsyncResult..ctor(SbmpResourceManager resourceManager, Transaction transaction, IRequestSessionChannel channel, SbmpMessageCreator messageCreator, Action`1 partitionInfoSetter, TimeSpan timeout, AsyncCallback callback, Object state) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpResourceManager.BeginEnlist(Transaction transaction, IRequestSessionChannel channel, SbmpMessageCreator messageCreator, Action`1 partitionInfoSetter, TimeSpan timeout, AsyncCallback callback, Object state) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<>c__DisplayClass38.<GetAsyncSteps>b__32(TIteratorAsyncResult thisPtr, TimeSpan t, AsyncCallback c, Object s) 
     at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state) 
     at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.Start() 
    Exception rethrown at [0]: 
     at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.OnEndSend(IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.EnumerateSteps(CurrentThreadType state) 
    Exception rethrown at [1]: 
     at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result) 
     at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.RunSynchronously() 
     at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout) 
     at CryptoArb.Infrastructure.AzureStorage.ServiceBus.AzureServiceBusService.Send(String label, Object message) 

서비스 버스 코드 은 다음과 같습니다 : 나는 서비스 버스에 연결 문자열이 유효하고 검사가 주제와 구독을 사용하기 전에 존재하는지 확인하기 위해 장소에하고 있는가

public class AzureServiceBusService : IServiceBusService 
{ 
    public ISettingsService SettingsService { get; set; } 
    private NamespaceManager _namespaceManager; 
    private string _topic; 
    private TopicClient _topicClient; 
    private TopicDescription _topicDescription; 
    private string _connectionString; 
    private SubscriptionClient _subscriptionClient; 
    private string _subscriptionName = "AllMessages"; 

    public string Topic 
    { 
     get { return _topic; } 
     set 
     { 
      _topic = value; 
      _topicDescription = null; 
      _topicClient = null; 
     } 

    } 
    public SubscriptionClient SubscriptionClient 
    { 
     get 
     { 
      if (_subscriptionClient != null) return _subscriptionClient; 
      if (!NamespaceManager.SubscriptionExists(TopicDescription.Path, _subscriptionName)) 
       NamespaceManager.CreateSubscription(TopicDescription.Path, _subscriptionName); 
      _subscriptionClient = SubscriptionClient.CreateFromConnectionString(ConnectionString, TopicDescription.Path, 
       _subscriptionName); 

      return _subscriptionClient; 
     } 
    } 


    internal string ConnectionString 
    { 
     get 
     { 
      if (String.IsNullOrWhiteSpace(_connectionString)) 
       _connectionString = SettingsService.ConnectionStrings[SettingsService.MainServiceBusConfigName].ConnectionString; 

      return _connectionString; 
     } 
    } 


    internal TopicClient TopicClient 
    { 
     get { 
      return _topicClient ?? 
        (_topicClient = TopicClient.CreateFromConnectionString(ConnectionString, TopicDescription.Path)); 
     } 
    } 

    internal TopicDescription TopicDescription 
    { 
     get 
     { 
      if (_topicDescription != null) return _topicDescription; 
      if (!NamespaceManager.TopicExists(_topic)) 
       NamespaceManager.CreateTopic(_topic); 
      _topicDescription = NamespaceManager.GetTopic(_topic); 
      return _topicDescription; 
     } 
    } 

    internal NamespaceManager NamespaceManager 
    { 
     get { 
      if (_namespaceManager == null) 
      { 
       _namespaceManager = NamespaceManager.CreateFromConnectionString(ConnectionString); 
       _namespaceManager.Settings.RetryPolicy = RetryExponential.Default; 
      } 
      return _namespaceManager; 
     } 
    } 

    public AzureServiceBusService() 
    { 
     _topic = "default"; 
    } 
    public AzureServiceBusService(string topic) 
    { 
     _topic = topic; 
    } 

    public void Send(string label, object message) 
    { 
     var brokeredMessage = new BrokeredMessage(message) 
     { 
      Label = label, 
     }; 
     brokeredMessage.Properties["messageType"] = message.GetType().AssemblyQualifiedName; 
     TopicClient.Send(brokeredMessage); 
    } 

    public ServiceBusMessage Receive() 
    { 
     var receivedMessage = SubscriptionClient.Receive(); 
     if (receivedMessage == null) 
      return null; 
     else 
     { 
      try 
      { 
       Type messageBodyType = null; 
       if (receivedMessage.Properties.ContainsKey("messageType")) 
        messageBodyType = Type.GetType(receivedMessage.Properties["messageType"].ToString()); 
       if (messageBodyType == null) 
       { 
        //Should never get here as a messagebodytype should 
        //always be set BEFORE putting the message on the queue 
        receivedMessage.DeadLetter(); 
       } 
       var method = typeof(BrokeredMessage).GetMethod("GetBody", new Type[] { }); 
       var generic = method.MakeGenericMethod(messageBodyType); 
       var messageBody = generic.Invoke(receivedMessage, null); 
       var serviceBusMessage = new ServiceBusMessage() 
       { 
        Body = messageBody, 
        MessageId = receivedMessage.MessageId 
       }; 

       receivedMessage.Complete(); 
       return serviceBusMessage; 
      } 
      catch (Exception e) 
      { 
       receivedMessage.Abandon(); 
       return null; 
      } 
     } 
    } 

    public string SubscriptionName 
    { 
     get { return _subscriptionName; } 
     set { _subscriptionName = value; } 
    } 
} 

.

예외가 발생하는 이유는 무엇입니까?

답변

1

다른 거래가 아닌지 확인하십시오. 가 자신의 IsolationLevel와 코드를 분리하려면, 아니 ... 그것은 TransactionScope에 만들어지지 않습니다

using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, 
     new TransactionOptions {IsolationLevel = IsolationLevel.Serializable})) 
{ 
    ...sending to the queue 

    transaction.Complete(); 
} 
2

Send 메서드를 호출하는 코드가 TransactionScope를 생성합니까? 그렇다면 isolotaionLevel이 Serializable로 설정되어 있는지 확인하십시오.

+0

으로 포장 할 수 있습니다. 그게 뭔 소리 야? –

관련 문제