1 people like it.

Publish expiring EasyNetQ messages

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
open System
open EasyNetQ

// Publish a message via EasyNetQ. If it's not delivered within
// the TimeSpan given, RabbitMQ will discard it without delivering.
let expiringPublish<'a when 'a : not struct> (bus : IBus) message (expire : TimeSpan) topic =
    let dms = bus.Advanced.Container.Resolve<IMessageDeliveryModeStrategy>()
    let ped = bus.Advanced.Container.Resolve<Producer.IPublishExchangeDeclareStrategy>()
    let messageType = typeof<'a>
    let props = MessageProperties(Expiration = (expire.TotalMilliseconds |> int |> string), DeliveryMode = dms.GetDeliveryMode(messageType))
    let enqMessage = Message<'a>(message, props)
    let exchange = ped.DeclareExchange(bus.Advanced, messageType, Topology.ExchangeType.Topic)
    let finalTopic =
        match topic with
        | Some t -> t
        | None -> bus.Advanced.Conventions.TopicNamingConvention.Invoke messageType
    bus.Advanced.Publish(exchange, finalTopic, false, false, enqMessage)
namespace System
namespace EasyNetQ
val expiringPublish : bus:IBus -> message:'a -> expire:TimeSpan -> topic:string option -> unit (requires reference type)

Full name: Script.expiringPublish
val not : value:bool -> bool

Full name: Microsoft.FSharp.Core.Operators.not
val bus : IBus
type IBus =
  member Advanced : IAdvancedBus
  member IsConnected : bool
  member Publish<'T> : message:'T -> unit + 1 overload
  member PublishAsync<'T> : message:'T -> Task + 1 overload
  member Receive<'T> : queue:string * onMessage:Action<'T> -> IDisposable + 5 overloads
  member Request<'TRequest, 'TResponse> : request:'TRequest -> 'TResponse
  member RequestAsync<'TRequest, 'TResponse> : request:'TRequest -> Task<'TResponse>
  member Respond<'TRequest, 'TResponse> : responder:Func<'TRequest, 'TResponse> -> IDisposable + 1 overload
  member RespondAsync<'TRequest, 'TResponse> : responder:Func<'TRequest, Task<'TResponse>> -> IDisposable + 1 overload
  member Send<'T> : queue:string * message:'T -> unit
  ...

Full name: EasyNetQ.IBus
val message : 'a (requires reference type)
val expire : TimeSpan
Multiple items
type TimeSpan =
  struct
    new : ticks:int64 -> TimeSpan + 3 overloads
    member Add : ts:TimeSpan -> TimeSpan
    member CompareTo : value:obj -> int + 1 overload
    member Days : int
    member Duration : unit -> TimeSpan
    member Equals : value:obj -> bool + 1 overload
    member GetHashCode : unit -> int
    member Hours : int
    member Milliseconds : int
    member Minutes : int
    ...
  end

Full name: System.TimeSpan

--------------------
TimeSpan()
TimeSpan(ticks: int64) : unit
TimeSpan(hours: int, minutes: int, seconds: int) : unit
TimeSpan(days: int, hours: int, minutes: int, seconds: int) : unit
TimeSpan(days: int, hours: int, minutes: int, seconds: int, milliseconds: int) : unit
val topic : string option
val dms : IMessageDeliveryModeStrategy
property IBus.Advanced: IAdvancedBus
property IAdvancedBus.Container: IContainer
IServiceProvider.Resolve<'TService (requires reference type)>() : 'TService
type IMessageDeliveryModeStrategy =
  member GetDeliveryMode : messageType:Type -> byte

Full name: EasyNetQ.IMessageDeliveryModeStrategy
val ped : Producer.IPublishExchangeDeclareStrategy
namespace EasyNetQ.Producer
type IPublishExchangeDeclareStrategy =
  member DeclareExchange : advancedBus:IAdvancedBus * exchangeName:string * exchangeType:string -> IExchange + 1 overload
  member DeclareExchangeAsync : advancedBus:IAdvancedBus * exchangeName:string * exchangeType:string -> Task<IExchange> + 1 overload

Full name: EasyNetQ.Producer.IPublishExchangeDeclareStrategy
val messageType : Type
val typeof<'T> : Type

Full name: Microsoft.FSharp.Core.Operators.typeof
val props : MessageProperties
Multiple items
type MessageProperties =
  new : unit -> MessageProperties + 1 overload
  member AppId : string with get, set
  member AppIdPresent : bool with get, set
  member ClusterId : string with get, set
  member ClusterIdPresent : bool with get, set
  member ContentEncoding : string with get, set
  member ContentEncodingPresent : bool with get, set
  member ContentType : string with get, set
  member ContentTypePresent : bool with get, set
  member CopyFrom : basicProperties:IBasicProperties -> unit
  ...

Full name: EasyNetQ.MessageProperties

--------------------
MessageProperties() : unit
MessageProperties(basicProperties: RabbitMQ.Client.IBasicProperties) : unit
property TimeSpan.TotalMilliseconds: float
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
Multiple items
type DeliveryModeAttribute =
  inherit Attribute
  new : isPersistent:bool -> DeliveryModeAttribute
  member IsPersistent : bool with get, set

Full name: EasyNetQ.DeliveryModeAttribute

--------------------
DeliveryModeAttribute(isPersistent: bool) : unit
IMessageDeliveryModeStrategy.GetDeliveryMode(messageType: Type) : byte
val enqMessage : Message<'a> (requires reference type)
Multiple items
type Message<'T (requires reference type)> =
  new : body:'T -> Message<'T> + 1 overload
  member Body : 'T with get, set
  member GetBody : unit -> obj
  member MessageType : Type with get, set
  member Properties : MessageProperties with get, set
  member SetProperties : properties:MessageProperties -> unit

Full name: EasyNetQ.Message<_>

--------------------
Message(body: 'T) : unit
Message(body: 'T, properties: MessageProperties) : unit
val exchange : Topology.IExchange
Producer.IPublishExchangeDeclareStrategy.DeclareExchange(advancedBus: IAdvancedBus, messageType: Type, exchangeType: string) : Topology.IExchange
Producer.IPublishExchangeDeclareStrategy.DeclareExchange(advancedBus: IAdvancedBus, exchangeName: string, exchangeType: string) : Topology.IExchange
namespace EasyNetQ.Topology
type ExchangeType =
  static val Direct : string
  static val Topic : string
  static val Fanout : string
  static val Header : string

Full name: EasyNetQ.Topology.ExchangeType
field Topology.ExchangeType.Topic = "topic"
val finalTopic : string
union case Option.Some: Value: 'T -> Option<'T>
val t : string
union case Option.None: Option<'T>
property IAdvancedBus.Conventions: IConventions
property IConventions.TopicNamingConvention: TopicNameConvention
TopicNameConvention.Invoke(messageType: Type) : string
IAdvancedBus.Publish<'T (requires reference type)>(exchange: Topology.IExchange, routingKey: string, mandatory: bool, immediate: bool, message: IMessage<'T>) : unit
IAdvancedBus.Publish(exchange: Topology.IExchange, routingKey: string, mandatory: bool, immediate: bool, messageProperties: MessageProperties, body: byte []) : unit
Raw view Test code New version

More information

Link:http://fssnip.net/sF
Posted:9 years ago
Author:
Tags: