Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 2.0.3
    • Fix Version/s: 2.0.4
    • Component/s: Core
    • Labels:
      None

      Activity

      Hide
      Oleg Zhurakousky added a comment -

      Custom UUID generation can no be provided by configuring a bean inside of the Application Context as an instance of MessageHeaders.IdGenerator strategy interface:

      public static interface IdGenerator {
      	UUID generateId();
      }
      

      For example:
      Your implementation

      public class MyIdGenerator implements IdGenerator {
      	public UUID generateId(){
      		return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());
      	}
      }
      

      XML Configuration

      <bean class="foo.bar.MyIdGenerator"/>
      

      It is important to understand that the instance of the IdGenerator will be injected as static field into MessageHeaders where Message ID is generated. Since its a static field it is one per class loader. We also recognize the Application Context lifecycle which means if the ApplicationContext which registered IdGenerator is closed this IdGenerator will be unset from the MessageHeaders and replaced with the default strategy (UUID.randomUUID()). However we do not allow changing IdGenerator in flight. This means that if an attempt is made to register a new IdGenerator when one was already set (e.g., two ApplicationContexts in the same Class Loader), the exception will be thrown.

      The good thing is that since we allowing for such configuration to be part of Spring's Application Context it could leverage everything that spring has to offer (e.g., DataAccess support, Dependency Injection etc.)

      Show
      Oleg Zhurakousky added a comment - Custom UUID generation can no be provided by configuring a bean inside of the Application Context as an instance of MessageHeaders.IdGenerator strategy interface: public static interface IdGenerator { UUID generateId(); } For example: Your implementation public class MyIdGenerator implements IdGenerator { public UUID generateId(){ return UUID.nameUUIDFromBytes((( System .currentTimeMillis() - System .nanoTime()) + "").getBytes()); } } XML Configuration <bean class= "foo.bar.MyIdGenerator" /> It is important to understand that the instance of the IdGenerator will be injected as static field into MessageHeaders where Message ID is generated. Since its a static field it is one per class loader. We also recognize the Application Context lifecycle which means if the ApplicationContext which registered IdGenerator is closed this IdGenerator will be unset from the MessageHeaders and replaced with the default strategy (UUID.randomUUID()). However we do not allow changing IdGenerator in flight. This means that if an attempt is made to register a new IdGenerator when one was already set (e.g., two ApplicationContexts in the same Class Loader), the exception will be thrown. The good thing is that since we allowing for such configuration to be part of Spring's Application Context it could leverage everything that spring has to offer (e.g., DataAccess support, Dependency Injection etc.)

        People

        • Assignee:
          Oleg Zhurakousky
          Reporter:
          Oleg Zhurakousky
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: