YCStompClient 1.0

YCStompClient 1.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新版本2014年12月

Fabio Knoedt 维护。



  • Fabio Knoedt

Objective-C 的 STOMP 客户端

这是基于 [https://github.com/juretta/objc-stomp] 的一个简单的 STOMP 客户端,支持 Stomp v1.1 和 v1.2。

使用方法

这个库是为了与 SocketRocket [https://github.com/square/SocketRocket] 一起使用而创建的。但应该可以与其它 WebSocket 库一起使用。

将 YCStompClient.{h,m} 添加到您的项目中。

MyExample.h

#import <Foundation/Foundation.h>

@class YCStompClient;
@protocol YCStompClientDelegate;


@interface MyExample : NSObject<YCStompClientDelegate> {
    @private
    YCStompClient *service;
}
@property(nonatomic, retain) YCStompClient *service;

@end

在 MyExample.m 中

#define kUsername   @"USERNAME"
#define kPassword   @"PASS"
#define kQueueName  @"/topic/systemMessagesTopic"

[...]

-(void) aMethod {
    YCStompClient *s = [[YCStompClient alloc] 
            initWithHost:@"localhost" 
                    port:61613 
                    login:kUsername
                passcode:kQueueName
                delegate:self];
    [s connect];


    NSDictionary *headers = [NSDictionary dictionaryWithObjectsAndKeys:     
            @"client", @"ack", 
            @"true", @"activemq.dispatchAsync",
            @"1", @"activemq.prefetchSize", nil];
    [s subscribeToDestination:kQueueName withHeader: headers];

    [self setService: s];
    [s release];
}

#pragma mark YCStompClientDelegate
- (void)stompClientDidConnect:(YCStompClient *)stompService {
        NSLog(@"stompServiceDidConnect");
}

- (void)stompClient:(YCStompClient *)stompService messageReceived:(NSString *)body withHeader:(NSDictionary *)messageHeader {
    NSLog(@"gotMessage body: %@, header: %@", body, messageHeader);
    NSLog(@"Message ID: %@", [messageHeader valueForKey:@"message-id"]);
    // If we have successfully received the message ackknowledge it.
    [stompService ack: [messageHeader valueForKey:@"message-id"]];
}

- (void)dealloc {
    [service unsubscribeFromDestination: kQueueName];
    [service release];
    [super dealloc];
}

支持

在 iOS5+ 上运行良好,并支持 ARC。

贡献者

原始代码

  • Scott Raymond
  • Stefan Saasen
  • Graham Haworth
  • jbg

此版本

  • Fabio Knoedt