1 /* 2 * hunt-amqp-client: AMQP Client Library for D Programming Language. Support for RabbitMQ and other AMQP Server. 3 * 4 * Copyright (C) 2018-2019 HuntLabs 5 * 6 * Website: https://www.huntlabs.net 7 * 8 * Licensed under the Apache-2.0 License. 9 * 10 */ 11 module hunt.amqp.client.impl.AmqpMessageBuilderImpl; 12 13 import hunt.amqp.client.AmqpMessage; 14 import hunt.amqp.client.AmqpMessageBuilder; 15 import hunt.amqp.client.impl.AmqpMessageImpl; 16 17 //import hunt.core.buffer.Buffer; 18 //import hunt.core.json.JsonArray; 19 //import hunt.core.json.JsonObject; 20 import hunt.proton.amqp.Binary; 21 import hunt.proton.amqp.Symbol; 22 import hunt.proton.amqp.messaging.AmqpValue; 23 import hunt.proton.amqp.messaging.ApplicationProperties; 24 import hunt.proton.amqp.messaging.Data; 25 import hunt.proton.message.Message; 26 import hunt.Exceptions; 27 import hunt.String; 28 //import java.sql.Date; 29 //import java.time.Instant; 30 import hunt.collection.List; 31 import hunt.collection.Map; 32 //import hunt.collection.UUID; 33 34 class AmqpMessageBuilderImpl : AmqpMessageBuilder { 35 36 private Message message; 37 38 this() { 39 message = Message.Factory.create(); 40 } 41 42 this(AmqpMessage existing) { 43 message = existing.unwrap(); 44 } 45 46 this(Message existing) { 47 message = existing; 48 } 49 50 51 public AmqpMessage build() { 52 return new AmqpMessageImpl(message); 53 } 54 55 56 public AmqpMessageBuilderImpl priority(short priority) { 57 message.setPriority(priority); 58 return this; 59 } 60 61 public AmqpMessageBuilder durable(bool durable) { 62 message.setDurable(durable); 63 return this; 64 } 65 66 67 public AmqpMessageBuilderImpl id(string id) { 68 message.setMessageId(new String(id)); 69 return this; 70 } 71 72 73 public AmqpMessageBuilderImpl address(string address) { 74 message.setAddress(new String(address)); 75 return this; 76 } 77 78 79 public AmqpMessageBuilderImpl replyTo(string replyTo) { 80 message.setReplyTo(new String(replyTo)); 81 return this; 82 } 83 84 85 public AmqpMessageBuilderImpl correlationId(string correlationId) { 86 message.setCorrelationId(new String(correlationId)); 87 return this; 88 } 89 90 91 public AmqpMessageBuilderImpl withBody(string value) { 92 message.setBody(new AmqpValue(new String(value))); 93 return this; 94 } 95 96 97 public AmqpMessageBuilderImpl withSymbolAsBody(string value) { 98 implementationMissing(false); 99 // message.setBody(new AmqpValue(Symbol.valueOf(value))); 100 return this; 101 } 102 103 104 public AmqpMessageBuilderImpl subject(string subject) { 105 message.setSubject(new String(subject)); 106 return this; 107 } 108 109 110 public AmqpMessageBuilderImpl contentType(string ct) { 111 message.setContentType(new String(ct)); 112 return this; 113 } 114 115 116 public AmqpMessageBuilderImpl contentEncoding(string ct) { 117 message.setContentEncoding(new String(ct)); 118 return this; 119 } 120 121 122 public AmqpMessageBuilderImpl expiryTime(long expiry) { 123 message.setExpiryTime(expiry); 124 return this; 125 } 126 127 128 public AmqpMessageBuilderImpl creationTime(long ct) { 129 message.setCreationTime(ct); 130 return this; 131 } 132 133 134 public AmqpMessageBuilderImpl ttl(long ttl) { 135 message.setTtl(ttl); 136 return this; 137 } 138 139 public AmqpMessageBuilder firstAcquirer(bool first) { 140 message.setFirstAcquirer(first); 141 return this; 142 } 143 144 public AmqpMessageBuilder deliveryCount(int count) { 145 message.setDeliveryCount(count); 146 return this; 147 } 148 149 150 public AmqpMessageBuilderImpl groupId(string gi) { 151 message.setGroupId(new String(gi)); 152 return this; 153 } 154 155 156 public AmqpMessageBuilderImpl replyToGroupId(string rt) { 157 message.setReplyToGroupId(new String(rt)); 158 return this; 159 } 160 161 162 //public AmqpMessageBuilderImpl applicationProperties(JsonObject props) { 163 // ApplicationProperties properties = new ApplicationProperties(props.getMap()); 164 // message.setApplicationProperties(properties); 165 // return this; 166 //} 167 168 169 public AmqpMessageBuilderImpl withBooleanAsBody(bool v) { 170 implementationMissing(false); 171 // message.setBody(new AmqpValue(v)); 172 return this; 173 } 174 175 176 public AmqpMessageBuilderImpl withByteAsBody(byte v) { 177 implementationMissing(false); 178 //message.setBody(new AmqpValue(v)); 179 return this; 180 } 181 182 183 public AmqpMessageBuilderImpl withShortAsBody(short v) { 184 implementationMissing(false); 185 //message.setBody(new AmqpValue(v)); 186 return this; 187 } 188 189 190 public AmqpMessageBuilderImpl withIntegerAsBody(int v) { 191 implementationMissing(false); 192 // message.setBody(new AmqpValue(v)); 193 return this; 194 } 195 196 197 public AmqpMessageBuilderImpl withLongAsBody(long v) { 198 implementationMissing(false); 199 // message.setBody(new AmqpValue(v)); 200 return this; 201 } 202 203 204 public AmqpMessageBuilderImpl withFloatAsBody(float v) { 205 implementationMissing(false); 206 //message.setBody(new AmqpValue(v)); 207 return this; 208 } 209 210 211 public AmqpMessageBuilderImpl withDoubleAsBody(double v) { 212 implementationMissing(false); 213 //message.setBody(new AmqpValue(v)); 214 return this; 215 } 216 217 218 public AmqpMessageBuilderImpl withCharAsBody(char c) { 219 implementationMissing(false); 220 //message.setBody(new AmqpValue(c)); 221 return this; 222 } 223 224 225 // @GenIgnore(GenIgnore.PERMITTED_TYPE) 226 // public AmqpMessageBuilderImpl withInstantAsBody(Instant v) { 227 // implementationMissing(false); 228 // //message.setBody(new AmqpValue(Date.from(v))); 229 // return this; 230 // } 231 232 233 //@GenIgnore(GenIgnore.PERMITTED_TYPE) 234 //public AmqpMessageBuilderImpl withUuidAsBody(UUID v) { 235 // message.setBody(new AmqpValue(v)); 236 // return this; 237 //} 238 239 240 //public AmqpMessageBuilderImpl withListAsBody(List list) { 241 // message.setBody(new AmqpValue(list)); 242 // return this; 243 //} 244 245 246 //@GenIgnore(GenIgnore.PERMITTED_TYPE) 247 //public AmqpMessageBuilderImpl withMapAsBody(Map map) { 248 // message.setBody(new AmqpValue(map)); 249 // return this; 250 //} 251 252 253 //public AmqpMessageBuilderImpl withBufferAsBody(Buffer buffer) { 254 // message.setBody(new Data(new Binary(buffer.getBytes()))); 255 // return this; 256 //} 257 258 259 //public AmqpMessageBuilderImpl withJsonObjectAsBody(JsonObject json) { 260 // return contentType("application/json") 261 // .withBufferAsBody(json.toBuffer()); 262 //} 263 264 265 //public AmqpMessageBuilderImpl withJsonArrayAsBody(JsonArray json) { 266 // return contentType("application/json") 267 // .withBufferAsBody(json.toBuffer()); 268 //} 269 }